这是Rails指南的一个例子,点击save post按钮后,控制台会显示以下信息:
Started POST "/posts" for 127.0.0.1 at 2013-12-25 22:42:04 +0800 Processing by PostsController#create as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"CLalUww3gqnSlED0AWdou6P/U2qyavPqDiBANQOuYgA=", "post"=>{"title"=>"11", "text"=>"22"}, "commit"=>"Save Post"} (0.0ms) begin transaction (0.0ms) rollback transaction 被重定向到http://127.0.0.1:3000/posts Completed 302 Found in 16ms (ActiveRecord: 0.0ms)
Started GET "/posts" for 127.0.0.1 at 2013-12-25 22:42:04 +0800 Processing by PostsController#index as HTML Rendered posts/index.html.erb within layouts/application (15.6ms) Completed 500 Internal Server Error in 31ms
ActionView::Template::Error (undefined method `each' for nil:NilClass):
<th>Text</th>
</tr>
<% @posts.each do |post| %>
路由没问题,为什么post是nil?Rails 4.0.2 Ruby 2.0
PostsController#index
的代码。 - Koraktor