3

In my application, I have a RecipesController and a CommentsController. All comments belong to a recipe, and can be voted up. Here's a snippet from my routes.rb:

  resources :recipes do
    member do
      put 'vote_up'
      post 'comment'
    end

    resources :comments do
      member do
        put 'vote_up'
      end
    end
  end

If I run rake routes, I find the following route in the output:

vote_up_recipe_comment PUT    /recipes/:recipe_id/comments/:id/vote_up(.:format) {:action=>"vote_up", :controller=>"comments"}

The CommentsController has a method called vote_up.

Also, linking to the route works (from my view)

    <%= link_to 'Vote up', vote_up_recipe_comment_path(@recipe, comment), :method => 'put' %> <br />

However, clicking on that link gives me the following error:

Routing Error

No route matches "/recipes/7/comments/4/vote_up"

What am I missing? I'm not sure how to debug this, because as far as I can see the route should match.

2 Answers 2

5

I think that you get this error message because the request is made via HTTP GET method, not PUT.

In order to create links that use POST/PUT/DELETE method, your application should correctly load a Javascript Rails adapter.

Check that your app has jQuery (http://github.com/rails/jquery-ujs) or Prototype JS adapter and that your layout correctly loads it.

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

1 Comment

Thanks a lot, that did the trick. I indeed removed some of the javascript files. In hindsight, it's obvious, but it would've probably taken me a long time to find.
3

try the following tweak: send the put method as a symbol

<%= link_to 'Vote up', vote_up_recipe_comment_path(@recipe, comment), :method => :put %>

Comments

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.