I'm trying develop a reddit style site which allows users to vote on links. The voting feature goes beyond basic CRUD supported by resources :links
I've written the up/down actions and linked them to the view but I'm not sure how to handle routing. Could someone demonstrate how I would route to custom controller actions? I've attached开发者_Go百科 my files below. Thanks
I receive this error when I load the view
No route matches {:controller=>"links", :action=>"up"}
Links Controller https://gist.github.com/1272577
View https://gist.github.com/1272580
Routes https://gist.github.com/1272584
You can extend resources
mapping with this example:
resources :links do
member do
match :up
match :down
end
end
These actions must be available in LinksController class (same as new, create...). More in Ruby on Rails Guide: Rails Routing.
Tip: actions changing state of entity should not use GET verb. This is because search bots or accelerator may follow your voting links. You link should be:
<%= link_to "+", up_link_path, :method => :post, :rel => 'nofollow' %>
And in controller should modify your entinty only inside if request.post?
. You should still support GET to not cause 404s.
精彩评论