2011-04-04 230 views
1

//参见下面的更新路由问题

错误:

No route matches {:controller=>"conversations", :action=>"reply", :id=>nil, :board_id=>nil} 

参数转储:

{"board_id"=>"2", 
"id"=>"3"} 

登录:

Started GET "/boards/2/conversations/3/reply" for 127.0.0.1 at Mon Apr 04 23:40:59 +0200 2011 
    Processing by ConversationsController#reply as HTML 
    Parameters: {"board_id"=>"2", "id"=>"3"} 
    Board Load (0.1ms) SELECT "boards"."id" FROM "boards" WHERE ("boards"."id" = 2) LIMIT 1 
    Board Load (0.6ms) SELECT "boards".* FROM "boards" WHERE ("boards"."id" = 2) LIMIT 1 
Rendered conversations/_reply_form.html.erb (1.3ms) 
Rendered conversations/reply.html.erb within layouts/application (9.4ms) 
Completed in 30ms 

ActionView::Template::Error (No route matches {:controller=>"conversations", :action=>"reply", :id=>nil, :board_id=>nil}): 
    1: <%= form_for(@comment, :url => reply_board_conversation_url(:board_id=>@board_id, :id=>@conversation_id)) do |f| %> 
    2: <% if @comment.errors.any? %> 
    3:  <div id="error_explanation"> 
    4:  <h2><%= pluralize(@comment.errors.count, "error") %> prohibited this reply from being saved:</h2> 
    app/views/conversations/_reply_form.html.erb:1:in `_app_views_conversations__reply_form_html_erb__999049254_2171331720_2303070' 
    app/views/conversations/reply.html.erb:4:in `_app_views_conversations_reply_html_erb___838091718_2171408600_0' 

Rendered /opt/local/lib/ruby/gems/1.8/gems/actionpack-3.0.0/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.1ms) 
Rendered /opt/local/lib/ruby/gems/1.8/gems/actionpack-3.0.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (982.1ms) 
Rendered /opt/local/lib/ruby/gems/1.8/gems/actionpack-3.0.0/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (1001.7ms) 

在我的routes.rb ,其:

get '/boards/:board_id/conversations/:id/reply' => "conversations#reply", :as => :reply_board_conversation 
    post '/boards/:board_id/conversations/:id/reply' => "conversations#save_reply", :as => :reply_board_conversation 

    resources :boards do 
    resources :conversations 
    end 

有谁知道我在做什么错?提前致谢!

//更新:

找出参数。但是,现在我们有一个新的错误..看到输出:

Started GET "/boards/2/conversations/3/reply" for 127.0.0.1 at Tue Apr 05 11:29:52 +0200 2011 
    Processing by ConversationsController#reply as HTML 
    Parameters: {"board_id"=>"2", "conversation_id"=>"3"} 
    Board Load (0.2ms) SELECT "boards"."id" FROM "boards" WHERE ("boards"."id" = 2) LIMIT 1 
    Board Load (0.2ms) SELECT "boards".* FROM "boards" WHERE ("boards"."id" = 2) LIMIT 1 
Rendered conversations/_reply_form.html.erb (4.3ms) 
Rendered conversations/reply.html.erb within layouts/application (6.3ms) 
Completed in 26ms 

ActionView::Template::Error (undefined method `model_name' for NilClass:Class): 
    1: <%= form_for(@comment, :url => reply_board_conversation_url(:board_id=>@board.id, :id=>@conversation_id)) do |f| %> 
    2: <% if @comment.errors.any? %> 
    3:  <div id="error_explanation"> 
    4:  <h2><%= pluralize(@comment.errors.count, "error") %> prohibited this reply from being saved:</h2> 
    app/views/conversations/_reply_form.html.erb:1:in `_app_views_conversations__reply_form_html_erb__999049254_2174448800_2303070' 
    app/views/conversations/reply.html.erb:1:in `_app_views_conversations_reply_html_erb___838091718_2174498080_0' 

Rendered /opt/local/lib/ruby/gems/1.8/gems/actionpack-3.0.0/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.1ms) 
Rendered /opt/local/lib/ruby/gems/1.8/gems/actionpack-3.0.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (757.4ms) 
Rendered /opt/local/lib/ruby/gems/1.8/gems/actionpack-3.0.0/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (774.2ms) 

回答

1

您所提供的日志表示@board_id和@conversation_id变量是零。

确保您实际上将@board_id@conversation_id的值设置为ConversationsController的回复操作。我怀疑你要么填充board_id,要么忘记做一些像@board_id = params[:board_id]一样的东西。

更新 要回答你的问题的下一部分,我猜测@comment尚未实例。某处在你的控制器动作,你应该执行类似如下:

@comment = Comment.new(params[:comment] 

,如果没有任何形式的数据这应该从任何现有的表单数据,或者一个新的评论评论。

+0

好的,做了关于params的工作。但是,现在出现了一个新的错误:“未定义的方法'model_name'为NilClass:Class” - 任何其他提示? Thx .. – 2011-04-05 09:32:12

+0

回答扩展。 – 2011-04-05 15:19:33

0

@board_id@conversation_id变量都为零,因为它说的错误消息:

No route matches {:controller=>"conversations", 
        :action=>"reply", 
        :id=>nil, 
        :board_id=>nil 
       } 

注意这里的:id:board_id参数。