shi*_*bly 1 ruby routing ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.1
<li><%= link_to('More Commented', posts_morecommented_path) %></li>
Run Code Online (Sandbox Code Playgroud)
错误
ActiveRecord::RecordNotFound in PostsController#show
Couldn't find Post with id=morecommented
Request
Parameters:
{"id"=>"morecommented"}
Run Code Online (Sandbox Code Playgroud)
我在哪里做错了?
postscontroller #show action
def show @post = Post.find(params[:id]) ... end
Run Code Online (Sandbox Code Playgroud)
morecommented.html.erb
<% @moreCommented.each do |t| %>
<%= link_to t.title, :controller => '/posts', :action => 'show', :id => t.id %><br/>
<% end %>
Run Code Online (Sandbox Code Playgroud)
耙路线
post GET /posts/:id(.:format) {:action=>"show", :controller=>"posts"}
....
posts_morecommented /posts/morecommented(.:format) {:controller=>"posts", :action=>"morecommented"}
Run Code Online (Sandbox Code Playgroud)
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"
Run Code Online (Sandbox Code Playgroud)
在资源调用之前移动匹配
match "posts/morecommented" => "posts#morecommented"
resources :posts
Run Code Online (Sandbox Code Playgroud)
或者你可以做
resources :posts do
get :morecommented, on: :collection
end
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2603 次 |
最近记录: |