My route file looks like this:
scope :locslug/:userslug do
....
....
post 'rate/:stars' => 'articles#rate' :as => :rate_article
end
I’m trying to generate a form with an action that targets the rate action in articles. Ideally, when the form is submitted, a rating will either be created or updated. Elsewhere, I have that an article has_many ratings.
This doesn’t work:
= form_tag rate_article_path, :method=>'post', :id => "rate_article" do
=hidden_field_tag :article_id, @article.id
=hidden_field_tag :stars, 0
=hiden_field_tag :user, current_user.id
Help is very much appreciated. Thank you.
does rails shows some error? I think you have your route wrong: ‘rate/:stars’ tells rails to expect a parameter when you call rate_article_path (something link rate_article_path(5) for 5 stars)
you should have your route:
your form:
now on your controller
(it’s really simplified, you should do some validations, it’s just to get the idea of what to do)