Ruby on Rails: the name of the form with form_for

Monday, April 21, 2008

Whenever I work with forms in rails, I get so confused. The API documentation is not really clear regarding how to set a name for the form. There are other places that I get confused, but I will solve one problem at a time. The form_tag takes three arguments.

  1. The first argument is the url or action, and you can use the url_for syntax. This can be a string or a hash.
  2. The html options go into the second argument. This is where I would add a name option. It should be inside a hash.
  3. You can put more options in the third argument. This will be a hash.

This is what you would use for use in rails...

<% form_for ({:action => "update", :id => @user}, {:name => "myForm" }, {}) do { -%> ... <% end -%>

The output should look like this...

...

blog comments powered by Disqus

Greg Hewett

Greg Hewett

Find me on various social networks:

Blogroll

Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Cras ornare mattis nunc. Mauris venenatis, pede sed aliquet vehicula, lectus tellus pulvinar neque, non cursus sem nisi vel augue.

Incremental leading

Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Cras ornare mattis nunc. Mauris venenatis, pede sed aliquet vehicula, lectus tellus pulvinar neque, non cursus sem nisi vel augue. sed aliquet vehicula, lectus tellus.