<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"}
我错在哪里?
后控制器显示动作
def show @post = Post.find(params[:id]) ... end
更多评论.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"}
路由.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"
最佳答案
在资源调用之前移动匹配项
match "posts/morecommented" => "posts#morecommented"
resources :posts
或者你也可以
resources :posts do
get :morecommented, on: :collection
end
关于ruby-on-rails - ActiveRecord::RecordNotFound在PostsController#show中单击链接,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8506969/