Search code examples
ruby-on-railsajaxrating

Rails Gem: Ajaxful_rating route problem


I'm trying to get ajaxful_rating to work with my rails installation.

I have everything running find until a user clicks on a star to rate.

When I click a star, the browser url points http://localhost:3000/entries/1/rate?dimension=design&show_user_rating=false&small=true&stars=4 and I get this error: No route matches "/entries/1/rate"

But my routes say:

  resources :entries do
    collection do
       ...
    end
    member do
      post 'rate'
      put 'submit'
    end

Is there something I'm missing? Some js not included? All I have included is jquery right now.

Edit

try {
Element.update("ajaxful_rating_design_no-small_entry_1", "<ul class=\"ajaxful-rating\"><li class=\"show-value\" style=\"width: 60.0%\">Global rating average: 3.0 out of 5</li><li><a href=\"/entries/1/rate?dimension=design&amp;show_user_rating=false&amp;small=false&amp;stars=1\" class=\"stars-1\" data-method=\"post\" data-remote=\"true\" rel=\"nofollow\" title=\"Rate 1 out of 5\">1</a></li><li><a href=\"/entries/1/rate?dimension=design&amp;show_user_rating=false&amp;small=false&amp;stars=2\" class=\"stars-2\" data-method=\"post\" data-remote=\"true\" rel=\"nofollow\" title=\"Rate 2 out of 5\">2</a></li><li><a href=\"/entries/1/rate?dimension=design&amp;show_user_rating=false&amp;small=false&amp;stars=3\" class=\"stars-3\" data-method=\"post\" data-remote=\"true\" rel=\"nofollow\" title=\"Rate 3 out of 5\">3</a></li><li><a href=\"/entries/1/rate?dimension=design&amp;show_user_rating=false&amp;small=false&amp;stars=4\" class=\"stars-4\" data-method=\"post\" data-remote=\"true\" rel=\"nofollow\" title=\"Rate 4 out of 5\">4</a></li><li><a href=\"/entries/1/rate?dimension=design&amp;show_user_rating=false&amp;small=false&amp;stars=5\" class=\"stars-5\" data-method=\"post\" data-remote=\"true\" rel=\"nofollow\" title=\"Rate 5 out of 5\">5</a></li></ul>");
new Effect.Highlight("ajaxful_rating_design_no-small_entry_1",{});
} catch (e) { alert('RJS error:\n\n' + e.toString()); alert('Element.update(\"ajaxful_rating_design_no-small_entry_1\", \"<ul class=\\\"ajaxful-rating\\\"><li class=\\\"show-value\\\" style=\\\"width: 60.0%\\\">Global rating average: 3.0 out of 5</li><li><a href=\\\"/entries/1/rate?dimension=design&amp;show_user_rating=false&amp;small=false&amp;stars=1\\\" class=\\\"stars-1\\\" data-method=\\\"post\\\" data-remote=\\\"true\\\" rel=\\\"nofollow\\\" title=\\\"Rate 1 out of 5\\\">1</a></li><li><a href=\\\"/entries/1/rate?dimension=design&amp;show_user_rating=false&amp;small=false&amp;stars=2\\\" class=\\\"stars-2\\\" data-method=\\\"post\\\" data-remote=\\\"true\\\" rel=\\\"nofollow\\\" title=\\\"Rate 2 out of 5\\\">2</a></li><li><a href=\\\"/entries/1/rate?dimension=design&amp;show_user_rating=false&amp;small=false&amp;stars=3\\\" class=\\\"stars-3\\\" data-method=\\\"post\\\" data-remote=\\\"true\\\" rel=\\\"nofollow\\\" title=\\\"Rate 3 out of 5\\\">3</a></li><li><a href=\\\"/entries/1/rate?dimension=design&amp;show_user_rating=false&amp;small=false&amp;stars=4\\\" class=\\\"stars-4\\\" data-method=\\\"post\\\" data-remote=\\\"true\\\" rel=\\\"nofollow\\\" title=\\\"Rate 4 out of 5\\\">4</a></li><li><a href=\\\"/entries/1/rate?dimension=design&amp;show_user_rating=false&amp;small=false&amp;stars=5\\\" class=\\\"stars-5\\\" data-method=\\\"post\\\" data-remote=\\\"true\\\" rel=\\\"nofollow\\\" title=\\\"Rate 5 out of 5\\\">5</a></li></ul>\");\nnew Effect.Highlight(\"ajaxful_rating_design_no-small_entry_1\",{});'); throw e }

This is what my server says when I click on a rating.


Solution

  • Your application is sending a GET request (the parameters are passed in the URL), but you declared a POST route.

    Changing post 'rate' to get 'rate' will allow this request to go through.

    The other possibility is that your application is generating a GET on the client side when it should be generating a POST. I'd need to look at your view code to diagnose that one.