Home
Ruby on Rails
Cheatsheets
form_for is used to easily manipulate HTML forms which are based upon ActiveRecord model objects:
<%= form_for(:customer, @customer, :url => { :controller => "customers", :action => "create" }, :html => { :multipart => true, :method => :put }) do |f| %> <%= f.text_field :age %> <%= text_field "customer", :age %> <%= submit_tag %> <% end %>
|
|
:symbol or "string" |
The name of the model object for all the fields in the form. All input fields will be prefixed with this. Rails will also look for an |
|
|
ActiveRecord model object |
If the |
|
|
"string" or {hash} |
The URL to post the form to. Can take an explicit url as a string, or a hash in the same format as |
|
|
{hash} |
A {hash} of HTML attributes which will be added to the HTML |
|
|
:symbol |
Pass as part of the {hash} of HTML attributes. Can be |
Sometimes you want to quickly see the output of helper methods, and constantly clicking refresh in your browser then viewing the page source can be tiresome. Instead, use the Rails console to check helpers are doing what you want them to.
More