小编Oat*_*eal的帖子

Rspec:2级嵌套资源的控制器规范

我的routes.rb

  namespace :magazine do
   resources :pages do
     resources :articles do
       resources :comments
     end
   end
  end
Run Code Online (Sandbox Code Playgroud)

在为评论编写控制器规范时:

describe "GET 'index'" do
    before(:each) do
     @user = FactoryGirl.create(:user)
     @page = FactoryGirl.build(:page)
     @page.creator = @user
     @page.save
     @article = FactoryGirl.create(:article)
     @comment_attributes = FactoryGirl.attributes_for(:comment, :article_id => @article )
   end
it "populates an array of materials" do
  get :index, ??
  #response.should be_success
  assigns(:comments)
end

it "renders the :index view" do
  get :index, ?? 
  response.should render_template("index")
end

end 
Run Code Online (Sandbox Code Playgroud)

任何想法如何给页面和文章引用get:index ?? 如果我给:get:index,:article_id => @ article.id
我得到的错误如下:

 Failure/Error: get :index, …
Run Code Online (Sandbox Code Playgroud)

controller rspec ruby-on-rails

22
推荐指数
2
解决办法
1万
查看次数

如何使用rspec在控制器中测试自定义路由

我在routes.rb中定义了一个自定义路由

get "packages/city/:location_id",  to: "packages#index"
Run Code Online (Sandbox Code Playgroud)

controller_spec.rb,

get :index
Run Code Online (Sandbox Code Playgroud)

给出了这个错误,

ActionController::UrlGenerationError:
   No route matches {:action=>"index", :controller=>"packages"}
Run Code Online (Sandbox Code Playgroud)

如何在控制器规范中明确指定自定义路由?

testing controller rspec ruby-on-rails

9
推荐指数
2
解决办法
8031
查看次数

使用带有MySQL2 gem的预处理语句?

如何在MySQL中创建预备语句insertselect查询?我正在使用MySQL2 gem,我的连接对象如下所示:

 con = Mysql2::Client.new(:host => "#{ENV['DB_HOST']}", :port => '3306', :username => "#{ENV['DB_UNAME']}", :password => "#{ENV['DB_PWD']}", :database => 'dbname')
Run Code Online (Sandbox Code Playgroud)

ruby prepared-statement mysql2

3
推荐指数
1
解决办法
4102
查看次数

在ROR上使用ActionMailer发送电子邮件确认时出错

我正在使用Windows 7(64位)上的ROR开发一个网站.我正在尝试设置我的网站,以便在其上创建新登录的人收到确认电子邮件.我正在使用ActionMailer进行电子邮件确认发送.我正在尝试将其配置为使用Gmail SMTP服务器发送确认电子邮件.(这只是用于测试.一旦它工作,我可以在部署服务器上使用其他东西.)

我收到此错误:

   Application-specific password required
Run Code Online (Sandbox Code Playgroud)

以下是来自development.rb的代码段:

        config.action_mailer.raise_delivery_errors = true
        config.action_mailer.delivery_method = :smtp

        # these options are only needed if you choose smtp delivery
       config.action_mailer.smtp_settings = {
       :address        => 'smtp.gmail.com',
       :port           => 587,
       :domain         => 'gmail.com',
       :authentication => :login,
       :user_name      => 'my_login@gmail.com',
       :password       => 'my_application_specific_password'
       }
Run Code Online (Sandbox Code Playgroud)

为什么我收到此错误,即使我为此目的生成了一个新的应用程序专用密码并且正在使用它?如何解决这个问题?

ruby-on-rails actionmailer confirmation-email

2
推荐指数
1
解决办法
1771
查看次数

资源名称与模型/控制器名称不同时,Cancan的load_and_authorize_resource

在我的应用中,我有工作表控制器,模型名称是工作表,但我的路线如下

routes.rb
 namespace :magazine do
  resources :pages, :controller => "sheets" do
    resources :articles do
     resources :comments
Run Code Online (Sandbox Code Playgroud)

这样该网址将是magazine / page / 1 / article ...

在我的Article控制器中,如何调用工作表的load_and_authorize_resource,以便我可以访问相关工作表的文章。我试过了

load_and_authorize_resource :sheet, :class => 'Sheet', :parent => false
load_and_authorize_resource :through => :sheet 
Run Code Online (Sandbox Code Playgroud)

无法访问@ sheet.articles ......

resources ruby-on-rails cancan

2
推荐指数
1
解决办法
3036
查看次数