2

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 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

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I updated the routes file and ran 'rake routes' but this solution didn't work. I also replaced 'post' with 'put' since I'm trying to update attributes, didn't solve it either.
I changed 'post' to 'put' and also modified my view links <%= link_to '+', up_link_url(link), :method => :put %> <%= link.points %> Thanks for the help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.