Home
Ruby on Rails
Cheatsheets
When a form is submitted to a Rails application, the parameters are automatically translated by Rails into the params object which is accessible as a hash structure.
|
|
id=1 |
|
|
|
id=1&color=red |
|
|
|
user[name]=David |
|
|
|
user[address][city]=London |
|
|
|
user[address][street]=Road |
|
[] after the name of a model object, such as address[], will insert the id of the record you are editing into the input field, useful for editing multiple records on one form:|
|
address[4][country]=England |
|
|
|
address[4][town]=London |
|
text_field "address[]", :country text_field "address[]", :town text_field "address[]", :country text_field "address[]", :town |
{ :address => [
{ :country => "England", :town => "London" },
{ :country => "Australia", :town => "Sydney" }
]
}
|
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