【发布时间】:2011-12-14 15:20:48
【问题描述】:
<li><%= link_to('More Commented', posts_morecommented_path) %></li>
错误
ActiveRecord::RecordNotFound in PostsController#show
Couldn't find Post with id=morecommented
Request
Parameters:
{"id"=>"morecommented"}
我在哪里做错了?
postscontroller#show action
def show @post = Post.find(params[:id]) ... end
morecommented.html.erb
<% @moreCommented.each do |t| %>
<%= link_to t.title, :controller => '/posts', :action => 'show', :id => t.id %><br/>
<% end %>
搜索路线
post GET /posts/:id(.:format) {:action=>"show", :controller=>"posts"}
....
posts_morecommented /posts/morecommented(.:format) {:controller=>"posts", :action=>"morecommented"}
routes.rb:
resources :posts
match "posts/:id/categ" => "posts#categ"
match "posts/:id/tag_posts" => "posts#tag_posts"
match "posts/searcharchive" => "posts#searcharchive"
match "posts/morecommented" => "posts#morecommented"
【问题讨论】:
-
添加您的
PostsController#show操作代码和routes.rb或rake routes输出 -
@MarkW,为什么我现在要迁移数据库?什么意思?
-
@Bohdan,我已经更新了原来的帖子/问题。
-
在您的 routes.rb 文件中将
match "posts/morecommented" => "posts#morecommented"移动到调用resources :posts之前 -
@Gerry,再次查看原帖。
标签: ruby-on-rails ruby ruby-on-rails-3 routing ruby-on-rails-3.1