rails2.1自己写个blog,redirect_to时候的问题!求解

问题描述

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>&raquo; <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的页面报错的吗?
解决方案六:
能否将你的异常栈贴出来

时间: 2024-10-30 22:34:27

rails2.1自己写个blog,redirect_to时候的问题!求解的相关文章

如何快速地给自己写的blog加入色彩

下载 使用编辑,然后菜单里面的转换的功能转换为,存盘. .然后在浏览器里打开文件, 和 ,就可以实现色彩功能. 看看我作的一个例子: 如何快速地给自己写的blog加入色彩.

java-请问这个代码应该如何写,完全没有思路啊,求解

问题描述 请问这个代码应该如何写,完全没有思路啊,求解 这个怎么写代码啊,一点思路都没有,怎么办啊,求解????????开发思路"> 解决方案 借鉴一下,改改. public static void main(String[] args) { // TODO Auto-generated method stub Runtime runtime = Runtime.getRuntime(); System.out.println("占用内存:" + (runtime.to

用Windows Live Writer写CSDN BLOG

1.在安装的时候,或者增加博客账户的时候,输入自己的Blog   URL和账号.密码.如:   URL为:http://blog.csdn.net/xzknet/   账号为:xzknet 密码:******     2.选择API:   从下拉框中选择:Metaweblog   API   在Remote   posting   URL   for   your   weblog里输入:           http://blog.csdn.net/xzknet/services/metabl

求大神-c++ 求直线解析式 ,程序怎么写。

问题描述 c++ 求直线解析式 ,程序怎么写. 解决方案 其实就是二元一次方程求解.计算机求解可以google高斯消去法,或者行列式. 解决方案二: http://blog.csdn.net/ccjjnn19890720/article/details/5157067 解决方案三: http://wenku.baidu.com/link?url=WXUrlWUZGfxzdhXfCLRv6t9cCZ9aJV9Gc-Lj_PjiFd91s1WX0JVpYTJ7zXousY2HaQ7Lazp7C6qX

关于blog程序的几个零碎想法

中介交易 http://www.aliyun.com/zixun/aggregation/6858.html">SEO诊断 淘宝客 云主机 技术大厅 有时想想好笑,给别人出主意的,大概都是学雷锋不要钱的,反之也是害死人不偿命的. 所以受了鼓舞投真金白银的那位主,多看看多想想没错. 今天的想法都是关于blog的,因为我 认为blog实际上是互联网的精华部分,用句时髦的话来说,blog是web2.0的代表作. 想法一:制作发布blog日志的专用程序 现在有不少人开通了 不只一个blog,比如新

小麦苗BLOG文章索引

小麦苗BLOG文章索引            自从2014年7月1号开始写blog到2015年5月5日,历时10个月的时间,大概写了90篇文章,这blog多了就乱了,今天抽空出来整理整理,方便大家也方便自己阅读,本文将一直更新,另外,最后我把所有的blog文章全列出来,可能会有用.    小麦苗的所有文章:itpub文章链接-小麦苗.zip     2015年06月03日更新一次,我写的blog数量:109 篇    2015年07月03日更新一次,我写的blog数量:126 篇    2016

谈谈BLOG营销中的写作

中介交易 http://www.aliyun.com/zixun/aggregation/6858.html">SEO诊断 淘宝客 云主机 技术大厅 开展BLOG营销其实一个核心的任务就是写作,这个也是我向咨询的企业客户经常谈到的.为什么写作的作用在BLOG营销中如此突现?因为写作的目的不仅是为了展示企业文化和增加客户信任度,另外一个就是为了配合搜索引擎营销中的搜索引擎优化工作的执行. 如果您会写作,我相信!但是,并不是每个会写作的人都会写配合BLOG营销的文章. 那么接下来,我就谈谈BL

We can ignore the performance influence when use sync replication in PostgreSQL 9.1

PostgreSQL 9.1 提供了同步复制的能力,但是我一直担心同步复制必将带来较大的性能影响. 下面从单节点,多个异步复制节点,多个复制节点(含同步复制节点):以及同步事务,本地事务,异步事务这几个方面来测试一下同步复制带来的性能影响. 下面是测试过程和测试结果. 首先是测试环境如下 :  服务器配置 :  主库:   8核, 24G, 1块本地SAS10K转硬盘, 1块1GB网卡, x86服务器 standby库1:  8核, 8G,  1块本地SAS10K转硬盘, 1块1GB网卡, x8

利用CocoasPod在Swift项目中使用CorePlot

最近在研究可用的第三方的图标控件,然后网上搜了之后,感觉功能比较强大的就是CorePlot了,于是就开始研究如何部署到程序中.网上关于这方面的教程比较少,大部分都是objective-c的,而且历史也比较久远,后来找到一篇老外写的blog,讲述在swift中如何使用CorePlot(http://blog.alwold.com/2014/08/07/using-coreplot-with-swift-in-ios/),研究了好久,总算成功安装了.下面就一步一步介绍. 1. 建立工程 首先建立一个