问题描述
class TopicsController < ApplicationController # GET /topics # GET /topics.xml def index #@topics = Topic.find(:all) @topics = Topic.paginate :page => params[:page],:per_page => 5, :order => 'created_at DESC' respond_to do |format| format.html # index.html.erb format.xml { render :xml => @topics } end end # GET /topics/1 # GET /topics/1.xml def show @topic = Topic.find(params[:id]) #@replies = Reply.find_all_by_topic_id(params[:id]); @reply = Reply.new respond_to do |format| format.html # show.html.erb format.xml { render :xml => @topic } end end def create #@reply = Topic.find(params[:id]).replies.new(params[:comment]) @reply = Reply.new(params[:reply]) respond_to do |format| if @reply.save flash[:notice] = 'Reply was successfully created.' #redirect_to topic_path(:id => @reply.topic_id) redirect_to :controller=>"topics",:action => 'show', :id =>params[:id] #format.html { redirect_to :controller=>"topics",:action => "show",:id => @reply.topic_id } #format.xml { render :xml => @reply, :status => :created, :location => @reply } else format.html { render :controller=>"topics",:action => "show",:id => @reply.topic_id } #format.xml { render :xml => @reply.errors, :status => :unprocessable_entity } end end endend<h3>发表回复:</h3><% form_for :reply, :url=>{:action =>"create"},:html=>{:id=>'commentform'} do |f| %> <p><%= f.error_messages %></p><%= hidden_field_tag "reply[topic_id]",@topic.id%><p><%= f.text_field :author,:id=>'author',:size=>'11',:tabindex=>'1'%><label for="author"><small>您的大名</small></label></p><p><%= f.text_field :email,:id=>'email',:size=>'11',:tabindex=>'1'%><label for="email"><small>Mail (will not be published) (required)</small></label></p><p><%= f.text_area :body,:id=>'comment',:cols=>'60',:rows=>'10',:tabindex=>'4'%></p><p><input name="submit" type="image" src="/images/submit.png" id="submit" tabindex="5" value="Submit Comment" /></p><% end %>恢复后,报错 NoMethodError in TopicsController#createYou have a nil object when you didn't expect it!The error occurred while evaluating nil.call求给个解答,为什么是NoMethodError in TopicsController#create,另外数据库也没有写入数据问题补充:详细异常是: NoMethodError in Topics#createShowing topics/show.html.erb where line #9 raised:You have a nil object when you didn't expect it!The error occurred while evaluating nil.titleExtracted source (around line #9):6: <li class="month">Feb</li>7: </ul>8: <ul class="title">9: <li class="topic"><%= link_to "#{@topic.title}",:action=>'show',:id=>@topic.id%></li>10: <li class="postmeta">Post by newdir. Filed under <a href="http://www.jianglb.com/category/story/" title="显示心情美文的所有文章" rel="category tag">心情美文</a>. </li>11: </ul>12: <div class="clear"></div>RAILS_ROOT: E:/projects/ruby/cnetownApplication Trace | Framework Trace | Full Traceapp/views/topics/show.html.erb:9:in `_run_erb_47app47views47topics47show46html46erb'app/controllers/topics_controller.rb:39:in `create'app/controllers/topics_controller.rb:31:in `create'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_view/base.rb:338:in `send'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_view/base.rb:338:in `execute'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_view/template_handlers/compilable.rb:29:in `send'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_view/template_handlers/compilable.rb:29:in `render'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_view/template.rb:35:in `render'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_view/template.rb:22:in `render_template'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_view/base.rb:245:in `render_file'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:1108:in `render_for_file'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:865:in `render_with_no_layout'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:880:in `render_with_no_layout'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/layout.rb:251:in `render_without_benchmark'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/benchmarking.rb:51:in `render'D:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/core_ext/benchmark.rb:8:in `realtime'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/benchmarking.rb:51:in `render'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/mime_responds.rb:131:in `call'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/mime_responds.rb:131:in `custom'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/mime_responds.rb:160:in `call'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/mime_responds.rb:160:in `respond'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/mime_responds.rb:154:in `each'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/mime_responds.rb:154:in `respond'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/mime_responds.rb:107:in `respond_to'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:1162:in `send'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:1162:in `perform_action_without_filters'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/filters.rb:580:in `call_filters'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/filters.rb:573:in `perform_action_without_benchmark'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'D:/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/rescue.rb:201:in `perform_action_without_caching'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/caching/sql_cache.rb:13:in `perform_action'D:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/abstract/query_cache.rb:33:in `cache'D:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/query_cache.rb:8:in `cache'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/caching/sql_cache.rb:12:in `perform_action'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:529:in `send'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:529:in `process_without_filters'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/filters.rb:569:in `process_without_session_management_support'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/session_management.rb:130:in `process'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:389:in `process'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:149:in `handle_request'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:107:in `dispatch'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:104:in `synchronize'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:104:in `dispatch'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:120:in `dispatch_cgi'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:35:in `dispatch'D:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/webrick_server.rb:112:in `handle_dispatch'D:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/webrick_server.rb:78:in `service'D:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'D:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'D:/ruby/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'D:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start'D:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'D:/ruby/lib/ruby/1.8/webrick/server.rb:95:in `start'D:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `each'D:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `start'D:/ruby/lib/ruby/1.8/webrick/server.rb:23:in `start'D:/ruby/lib/ruby/1.8/webrick/server.rb:82:in `start'D:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/webrick_server.rb:62:in `dispatch'D:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/commands/servers/webrick.rb:66D:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'D:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'D:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:509:in `require'D:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:354:in `new_constants_in'D:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:509:in `require'D:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/commands/server.rb:39D:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'D:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'script/server:3app/views/topics/show.html.erb:9:in `_run_erb_47app47views47topics47show46html46erb'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_view/base.rb:338:in `send'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_view/base.rb:338:in `execute'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_view/template_handlers/compilable.rb:29:in `send'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_view/template_handlers/compilable.rb:29:in `render'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_view/template.rb:35:in `render'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_view/template.rb:22:in `render_template'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_view/base.rb:245:in `render_file'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:1108:in `render_for_file'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:865:in `render_with_no_layout'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:880:in `render_with_no_layout'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/layout.rb:251:in `render_without_benchmark'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/benchmarking.rb:51:in `render'D:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/core_ext/benchmark.rb:8:in `realtime'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/benchmarking.rb:51:in `render'app/controllers/topics_controller.rb:39:in `create'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/mime_responds.rb:131:in `call'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/mime_responds.rb:131:in `custom'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/mime_responds.rb:160:in `call'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/mime_responds.rb:160:in `respond'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/mime_responds.rb:154:in `each'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/mime_responds.rb:154:in `respond'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/mime_responds.rb:107:in `respond_to'app/controllers/topics_controller.rb:31:in `create'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:1162:in `send'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:1162:in `perform_action_without_filters'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/filters.rb:580:in `call_filters'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/filters.rb:573:in `perform_action_without_benchmark'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'D:/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/rescue.rb:201:in `perform_action_without_caching'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/caching/sql_cache.rb:13:in `perform_action'D:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/abstract/query_cache.rb:33:in `cache'D:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/query_cache.rb:8:in `cache'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/caching/sql_cache.rb:12:in `perform_action'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:529:in `send'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:529:in `process_without_filters'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/filters.rb:569:in `process_without_session_management_support'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/session_management.rb:130:in `process'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:389:in `process'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:149:in `handle_request'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:107:in `dispatch'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:104:in `synchronize'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:104:in `dispatch'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:120:in `dispatch_cgi'D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:35:in `dispatch'D:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/webrick_server.rb:112:in `handle_dispatch'D:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/webrick_server.rb:78:in `service'D:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'D:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'D:/ruby/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'D:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start'D:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'D:/ruby/lib/ruby/1.8/webrick/server.rb:95:in `start'D:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `each'D:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `start'D:/ruby/lib/ruby/1.8/webrick/server.rb:23:in `start'D:/ruby/lib/ruby/1.8/webrick/server.rb:82:in `start'D:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/webrick_server.rb:62:in `dispatch'D:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/commands/servers/webrick.rb:66D:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'D:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'D:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:509:in `require'D:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:354:in `new_constants_in'D:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:509:in `require'D:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/commands/server.rb:39D:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'D:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'script/server:3RequestParameters:{"submit"=>"Submit Comment", "reply"=>{"topic_id"=>"2", "body"=>"k", "author"=>"k", "email"=>"k"}, "authenticity_token"=>"19ab9874ff06d331f16b7c9f8db24a912544cf80", "id"=>"2", "submit.x"=>"68", "submit.y"=>"4"}Show session dump--- :csrf_id: 0d58824885dcd78c081210aeb1baedc3flash: !map:ActionController::Flash::FlashHash {}ResponseHeaders:{"cookie"=>[], "Content-Type"=>"text/html", "Cache-Control"=>"no-cache"}问题补充:log是:========================================================Rendering D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/templates/rescues/layout.erb (internal_server_error)Processing TopicsController#create (for 127.0.0.1 at 2008-06-25 17:42:19) [POST] Session ID: BAh7BzoMY3NyZl9pZCIlMGQ1ODgyNDg4NWRjZDc4YzA4MTIxMGFlYjFiYWVkYzMiCmZsYXNoSUM6J0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhhc2h7AAY6CkB1c2VkewA=--10afe59f5f8af0e333d166e5875872905bb5628f Parameters: {"submit"=>"Submit Comment", "reply"=>{"topic_id"=>"2", "body"=>"k", "author"=>"k", "email"=>"k"}, "authenticity_token"=>"19ab9874ff06d331f16b7c9f8db24a912544cf80", "action"=>"create", "id"=>"2", "submit.x"=>"68", "controller"=>"topics", "submit.y"=>"4"} [4;36;1mReply Columns (0.015000)[0m [0;1mSHOW FIELDS FROM `replies`[0m [4;35;1mSQL (0.000000)[0m [0mBEGIN[0m [4;36;1mSQL (0.000000)[0m [0;1mCOMMIT[0mRendering template within layouts/topicsRendering topics/showActionView::TemplateError (You have a nil object when you didn't expect it!The error occurred while evaluating nil.title) on line #9 of topics/show.html.erb:6: <li class="month">Feb</li>7: </ul>8: <ul class="title">9: <li class="topic"><%= link_to "#{@topic.title}",:action=>'show',:id=>@topic.id%></li>10: <li class="postmeta">Post by newdir. Filed under <a href="http://www.jianglb.com/category/story/" title="显示心情美文的所有文章" rel="category tag">心情美文</a>. </li>11: </ul>12: <div class="clear"></div> app/views/topics/show.html.erb:9:in `_run_erb_47app47views47topics47show46html46erb' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_view/base.rb:338:in `send' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_view/base.rb:338:in `execute' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_view/template_handlers/compilable.rb:29:in `send' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_view/template_handlers/compilable.rb:29:in `render' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_view/template.rb:35:in `render' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_view/template.rb:22:in `render_template' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_view/base.rb:245:in `render_file' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:1108:in `render_for_file' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:865:in `render_with_no_layout' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:880:in `render_with_no_layout' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/layout.rb:251:in `render_without_benchmark' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/benchmarking.rb:51:in `render' D:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/core_ext/benchmark.rb:8:in `realtime' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/benchmarking.rb:51:in `render' app/controllers/topics_controller.rb:39:in `create' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/mime_responds.rb:131:in `call' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/mime_responds.rb:131:in `custom' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/mime_responds.rb:160:in `call' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/mime_responds.rb:160:in `respond' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/mime_responds.rb:154:in `each' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/mime_responds.rb:154:in `respond' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/mime_responds.rb:107:in `respond_to' app/controllers/topics_controller.rb:31:in `create' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:1162:in `send' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:1162:in `perform_action_without_filters' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/filters.rb:580:in `call_filters' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/filters.rb:573:in `perform_action_without_benchmark' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue' D:/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/rescue.rb:201:in `perform_action_without_caching' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/caching/sql_cache.rb:13:in `perform_action' D:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/abstract/query_cache.rb:33:in `cache' D:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/query_cache.rb:8:in `cache' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/caching/sql_cache.rb:12:in `perform_action' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:529:in `send' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:529:in `process_without_filters' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/filters.rb:569:in `process_without_session_management_support' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/session_management.rb:130:in `process' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:389:in `process' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:149:in `handle_request' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:107:in `dispatch' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:104:in `synchronize' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:104:in `dispatch' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:120:in `dispatch_cgi' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:35:in `dispatch' D:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/webrick_server.rb:112:in `handle_dispatch' D:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/webrick_server.rb:78:in `service' D:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service' D:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run' D:/ruby/lib/ruby/1.8/webrick/server.rb:173:in `start_thread' D:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start' D:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start_thread' D:/ruby/lib/ruby/1.8/webrick/server.rb:95:in `start' D:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `each' D:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `start' D:/ruby/lib/ruby/1.8/webrick/server.rb:23:in `start' D:/ruby/lib/ruby/1.8/webrick/server.rb:82:in `start' D:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/webrick_server.rb:62:in `dispatch' D:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/commands/servers/webrick.rb:66 D:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require' D:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require' D:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:509:in `require' D:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:354:in `new_constants_in' D:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:509:in `require' D:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/commands/server.rb:39 D:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require' D:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require' script/server:3Rendering D:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/templates/rescues/layout.erb (internal_server_error)问题补充:topic和comment的回复时候报的错,comment的回复在topic show的erb上面。全代码如下:<div class="contain"><div id="content" class="narrowcolumn"><div class="post" id="post-77"><ul class="date"><li class="day">04</li><li class="month">Feb</li></ul><ul class="title"><li class="topic"><%= link_to "#{@topic.title}",:action=>'show',:id=>@topic.id%></li></ul><div class="clear"></div><div class="entry"><%=h @topic.description %><p class="meta"><small>» <a href="#comment">发布回复</a></small></p></div></div><!-- You can start editing here. --><h3 id="comments">共<%=@topic.replies.size%>条回复</h3> <ol class="commentlist"><% i=1for reply in @topic.repliesif i%2 == 0%><li class="alt" id="comment-4995"><%else%><li class="alttwo" id="comment-4995"><%end%> <cite>第<%=i%>楼 匿名人士</cite> 回复:<br /><small class="commentmetadata"><a href="#comment-<%=h reply.id %>" title=""><%=h reply.created_at.strftime("%Y-%m-%d %H:%M") %></a></small><%=h reply.body %></li><%i=i+1end%></ol><h3>发表回复:</h3><% form_for :reply, :url=>{:action =>"create",:id=>@topic.id},:html=>{:id=>'commentform'} do |f| %> <p><%= f.error_messages %></p><%= hidden_field_tag "reply[topic_id]",@topic.id%><p><%= f.text_field :author,:id=>'author',:size=>'11',:tabindex=>'1'%><label for="author"><small>您的大名</small></label></p><p><%= f.text_field :email,:id=>'email',:size=>'11',:tabindex=>'1'%><label for="email"><small>Mail (will not be published) (required)</small></label></p><p><%= f.text_area :body,:id=>'comment',:cols=>'60',:rows=>'10',:tabindex=>'4'%></p><p><input name="submit" type="image" src="/images/submit.png" id="submit" tabindex="5" value="Submit Comment" /></p><% end %>问题补充:comments_controller 无代码。。。。我以为全部都是在topic controller中操作了问题补充:respond_to do |format| if @reply.save flash[:notice] = 'Reply was successfully created.' #redirect_to topic_path(:id => @reply.topic_id) redirect_to :controller=>"topics",:action => 'show', :id =>params[:id] #format.html { redirect_to :controller=>"topics",:action => "show",:id => @reply.topic_id } 我是用的redirect_to :controller=>"topics",:action => 'show', :id =>params[:id] 呢
解决方案
这样应该没有问题的啊?redirect_to topic_path(:id => @reply.topic_id)redirect_to :controller=>"topics",:action => 'show', :id =>params[:id] redirect_to topic_url(:id => @reply.topic_id)这样都没问题的。这样吧,你通过站内短信把整个project发给我看下。
解决方案二:
像我这样的就可以if Post.find(params[:id]).comments.create(params[:post_comment]) flash[:tip] = "谢谢你的评论!" end redirect_to :action => "show" ,:id => params[:id]不应该使用response
解决方案三:
引用Parameters: {"submit"=>"Submit Comment", "reply"=>{"topic_id"=>"2", "body"=>"k", "author"=>"k", "email"=>"k"}, "authenticity_token"=>"19ab9874ff06d331f16b7c9f8db24a912544cf80", "action"=>"create", "id"=>"2", "submit.x"=>"68", "controller"=>"topics", "submit.y"=>"4"}[4;36;1mReply Columns (0.015000)[0m [0;1mSHOW FIELDS FROM `replies`[0m[4;35;1mSQL (0.000000)[0m [0mBEGIN[0m[4;36;1mSQL (0.000000)[0m [0;1mCOMMIT[0mRendering template within layouts/topicsRendering topics/show 看一下log日志,是不是你保存完了,render :action=>:show的呢?这里没有执行topic的查询,如果是这样的话,应该采用redirect_to :action=>:show.
解决方案四:
我写错了,应该是发表评论,然后转到topic show的页面,是不?如果是的话,能否将comments_controller 的代码贴出来看下。
解决方案五:
上面错误是因为: @topic为nil,所以才报错这个错误的。你的erb.html代码贴的是comment部分的代码,能否将topic的create代码贴出来。你是操作 create topic,然后转到topic show的页面报错的吗?
解决方案六:
能否将你的异常栈贴出来