Greg Hewett's Blog

Just a simple journal.

Ruby on Rails: The Name of the Form With Form_for

| Comments

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…

~~~ruby <% form_for ({:action => “update”, :id => @user}, {:name => “myForm” }, {}) do -%>

...

<% end %> ~~~

The output should look like this…

~~~html

...

~~~

Comments