Skip to content

Instantly share code, notes, and snippets.

Form_for

  • Most magical form helper in rails
  • form_for is a ruby method into which a ruby object is passed
  • form_for yields a form builder object (typically f)
  • methods to create form controls are called on f, the form builder element
  • when the object is passed as a form_for parameter, it creates corresponding inputs with each of the attributes
    • if i had form_for(@cat), then the form field params would look like cat[name], cat[color], etc
  • in keeping with Rails convention regarding RESTful routes, there should be a resource declared for each model object (eg, resources :cats)