You are here: Home Solidarrow Ruby on Rails Solidarrow Cheatsheets

* Form Helpers Cheatsheet

Create forms, check boxes, radio buttons, select lists and more using Rails' built-in form helpers.

RESTful form_for

When standard routes are used in a RESTful context, Rails will reflect upon the object passed to it and automatically build a form with the relevant RESTful URL depending on whether the form is wrapping a new record (create) or an existing record (update). Nested routes will require you to be more verbose. Standard routes

Standard routes

new record?

method

URL

form_for(@customer)

yes

POST

/customers

form_for(@customer)

no

PUT

/customers/1

Nested routes

new record?

method

URL

form_for(@address, :url => customer_addresses_path(@customer))

yes

POST

/customers/1/addresses

form_for(@address, :url => customer_addresses_path(@customer))

no

PUT

/customers/1/addresses/24

 

 

> RELATED ARTICLE

* Quickly debugging form helpers

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