19

I have a model 'Article' and a model 'Ratings' nested within articles.

/articles/123/ratings

I want to change the routing of the f.submit in ratings/_form.html.erb now it is so, that after pressing submit, my application routs to

/ratings/111

but I want to route it to

/article/123

How can I change the routing in a form_for f.submit button. I have found here something like this:

<% form_for :thing, :url => 
 url_for(:action => "update", :id => @thing) do |f| %>

But this do not work for my rails 3.2. Thanks for your help,

meawoppl
  • 2,714
  • 1
  • 23
  • 30
Lailo
  • 641
  • 1
  • 8
  • 24
  • You forgot to add `=` after `<%`. Unfortunately I did not understand at what controller and action you want to send the form. – Mik May 02 '12 at 14:09

2 Answers2

25

:url - The URL the form is submitted to. It takes the same fields you pass to url_for or link_to. In particular you may pass here a named route directly as well. Defaults to the current action.

<% form_for :thing, :url => {:action => "update", :id => @thing} do |f| %>

you can also pass it the path_name by using the helper. so you can also do something like

:url => update_article_path(@article)
Abid
  • 7,149
  • 9
  • 44
  • 51
  • no this do not work for me >> form_for(@rating), :url => (:action => "show", :id => @article) do |f| >> the error that I get are this >> syntax error, unexpected tASSOC, expecting keyword_end...nd= – Lailo May 02 '12 at 13:29
5

Try form_for (:thing, url:{:controller=>'thing', :action=>'update'}, html:{method:'put'}).

Andrey Deineko
  • 51,333
  • 10
  • 112
  • 145
Antonio Jha
  • 1,301
  • 13
  • 13