0 0

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

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
  end

end



<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#create

You have a nil object when you didn't expect it!
The error occurred while evaluating nil.call


求给个解答,为什么是NoMethodError in TopicsController#create,另外数据库也没有写入数据
问题补充:
详细异常是:


NoMethodError in Topics#create

Showing 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.title

Extracted 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/cnetown
Application Trace | Framework Trace | Full Trace

app/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: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:3

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:3

Request

Parameters:

{"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: 0d58824885dcd78c081210aeb1baedc3
flash: !map:ActionController::Flash::FlashHash {}


Response

Headers:

{"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: BAh7BzoMY3NyZl9pZCIlMGQ1ODgyNDg4NWRjZDc4YzA4MTIxMGFlYjFiYWVk
YzMiCmZsYXNoSUM6J0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhh
c2h7AAY6CkB1c2VkewA=--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"}
  Reply Columns (0.015000)   SHOW FIELDS FROM `replies`
  SQL (0.000000)   BEGIN
  SQL (0.000000)   COMMIT
Rendering template within layouts/topics
Rendering topics/show


ActionView::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:3

Rendering 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=1
for reply in @topic.replies
if 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+1
end%>
</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]   呢
2008年6月25日 17:20

6个答案 按时间排序 按投票排序

0 0

采纳的答案

这样应该没有问题的啊?

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发给我看下。

2008年6月26日 12:09
0 0

像我这样的就可以

if Post.find(params[:id]).comments.create(params[:post_comment])
      flash[:tip] = "谢谢你的评论!"    
    end
    redirect_to :action => "show" ,:id => params[:id]


不应该使用response

2008年6月27日 09:49
0 0

引用
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"}

Reply Columns (0.015000) SHOW FIELDS FROM `replies`
SQL (0.000000) BEGIN
SQL (0.000000) COMMIT
Rendering template within layouts/topics
Rendering topics/show


看一下log日志,是不是你保存完了,render :action=>:show的呢?这里没有执行topic的查询,如果是这样的话,应该采用redirect_to :action=>:show.

2008年6月25日 21:23
0 0

我写错了,应该是发表评论,然后转到topic show的页面,是不?如果是的话,能否将comments_controller 的代码贴出来看下。

2008年6月25日 17:59
0 0

上面错误是因为: @topic为nil,所以才报错这个错误的。你的erb.html代码贴的是comment部分的代码,能否将topic的create代码贴出来。

你是操作 create topic,然后转到topic show的页面报错的吗?

2008年6月25日 17:57
0 0

能否将你的异常栈贴出来

2008年6月25日 17:35

相关推荐

    RAILS2.1的中文版资料

    ### RAILS2.1的中文版资料:新特性与改进详解 #### 概述 《RAILS2.1的中文版资料》是一份针对Ruby on Rails 2.1版本的详细介绍文档,由Carlos Brando和Marcos Tapajós共同编写,并由中国Rails社区成员翻译成中文...

    What’s New In Rails 2.1

    ### Ruby on Rails 2.1 新特性详解 #### 引言 自2004年7月David Heinemeier Hansson公开发布Ruby on Rails框架以来,这一轻量级且功能强大的Web开发框架迅速赢得了全球开发者们的青睐。经过三年多的发展与优化,在...

    ruby on rails 2.1 what is new (CN)

    而在接下来的几个月里,全球超过1400名开发者为Rails贡献了1600多个补丁,最终在2008年6月1日,Ruby on Rails 2.1正式发布。这次版本更新不仅带来了诸多新特性,还进一步优化了原有的功能。 #### Ruby on Rails 2.1...

    ruby on rails 2.1新特性介绍

    ### Ruby on Rails 2.1新特性详尽解析 #### 概述 Ruby on Rails,一个备受推崇的Web开发框架,自2004年由David Heinemeier Hansson首次发布以来,便以其优雅的设计和“约定优于配置”的理念赢得了全球开发者的心。...

    rails2.1與Oracle 連結所需gem

    标题“rails2.1与Oracle连接所需gem”指的是在Rails 2.1版本的应用程序中,如何配置和使用Oracle数据库的宝石(gem)扩展。Rails是Ruby on Rails框架的简称,是一个流行的开源Web应用程序框架,而Oracle则是一种企业...

    rails 2.1 CHM api文档

    rails 2.1的api文档,chm格式,官方最新版

    RestFul_Rails_Dev_pdf_v_0.1.zip

    通过关联,可以方便地处理资源之间的关系,比如用户拥有多个博客文章(posts),文章属于特定用户。 总的来说,《RESTful Rails Development》这本书将帮助读者理解如何利用Rails的特性来构建符合REST原则的应用,...

    InspiniaAdmin 2.6.2.1 All_Seed_Project

    InspiniaAdmin 2.6.2.1 All_Seed_Project 这个包含所有的Seed Project! Angular_2_Seed_Project Angular_Seed_Project Angular_Seed_Project_Grunt Angular_Seed_Project_Gulp Angular_Seed_Project_MEANJS ASPNET_...

    Ruby rails 页面跳转(render和redirect_to)

    Ruby代码 代码如下:if @user.update_attributes(:password =&gt; params[:user][:password]) flash[:notice] = ‘密码修改完成’ redirect_to :action =&gt; ‘index’ else redirect_to :action =&gt; ‘change_pass’, :id ...

    rails_admin_acts_as_list:rails_admin插件以对记录进行排序

    介绍插件,用于对记录进行排序(使用 gem)安装要启用rails_admin_acts_as_list,请将以下内容添加到您的Gemfile : gem 'rails_admin_acts_as_list'gem 'rails_admin' 重要提示: rails_admin_acts_as_list之前必须...

    Rails_Recipes_with_Source_Code

    《Rails Recipes with Source Code》是一本专注于Ruby on Rails框架实践技巧和源代码解析的书籍。Rails是基于Ruby语言的Web开发框架,以其“约定优于配置”(Convention over Configuration)的理念和“开发人员的...

    用于过滤英文脏话的 Rails 插件 gem_Ruby_代码_相关文件_下载

    标题提到的"用于过滤英文脏话的 Rails 插件 gem"正是为了解决这个问题。这个插件允许开发者通过简单的配置,对输入的文本进行检查和替换,确保网站内容的清洁度和专业性。 这个插件名为`profanity_filter`,它是一...

    InspiniaAdmin 2.6.2.1 All_Full_Version

    InspiniaAdmin 2.6.2.1 All_Full_Version 包含所有的Full Version! Angular_Full_Version ASPNET_Core_1_0_Full_Project ASPNET_MVC5_Full_Version ASPNET_MVC6_RC_1_Full_Version Meteor_Full_Version Rails_Full_...

    rails_get_to_the_fest

    标题 "rails_get_to_the_fest" 暗示着这是一个关于Ruby on Rails的项目,可能是为某种节日或活动创建的Web应用。Rails是基于Ruby语言的开源Web开发框架,它遵循MVC(模型-视图-控制器)架构模式,使得构建数据库驱动...

    Ruby on Rails Guides v2 - Ruby on Rails 4.2.5

    ### Ruby on Rails Guides v2 - Ruby on Rails 4.2.5 #### 一、重要概念及基础假设 - **重要概念**:本指南旨在帮助读者深入理解Ruby on Rails(以下简称Rails)4.2.5版本的核心功能与最佳实践。 - **基础假设**:...

    rail 2.1 chm

    《Rails 2.1 API 深度解析》 Rails,全称为Ruby on Rails,是一款基于Ruby语言的开源Web应用程序...通过阅读《Rails 2.1 API》的CHM文档,开发者可以深入了解这个版本的各种特性和最佳实践,从而提升自己的开发技能。

    rails_model_test_hello_world

    自述文件版本和设置$ ruby -vruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-darwin18]$ rails -vRails 5.2.3使用我创建的特殊模板来加快开发过程。 # ~/rtfb_template.rbgroup :development , :test do gem '...

    Ruby-on-Rails-rails.zip

    Ruby_on_Rails_rails.zip Ruby_on_Rails_rails.zip Ruby_on_Rails_rails.zip Ruby_on_Rails_rails.zipRuby_on_Rails_rails.zip Ruby_on_Rails_rails.zip Ruby_on_Rails_rails.zip Ruby_on_Rails_rails.zipRuby_on_...

    使用Rails4Devise和Grape验证API_JavaScript_CSS_下载.zip

    标题中的“使用Rails4Devise和Grape验证API”揭示了这个项目是关于在Ruby on Rails 4框架中实现用户认证的。Devise是一个灵活的身份验证解决方案,它为Rails应用提供了许多常见的身份验证需求,如注册、登录、密码...

    Rails101_by_rails4.0

    《Rails101_by_rails4.0》是一本专注于Rails 4.0.0版本和Ruby 2.0.0版本的自学教程书籍,它定位于中文读者,旨在成为学习Rails框架的参考教材。Rails(Ruby on Rails)是一个采用Ruby语言编写的开源Web应用框架,它...

Global site tag (gtag.js) - Google Analytics