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.

  • Example - controller, view, HTML and params[]
  • fields_for - creates a scope around fields
  • Multipart form - model and view of multipart form
  • Input field helpers - check boxes, text fields, radio buttons
  • RESTful form_for - using form_for in a RESTful context
  • form_for - wrap ActiveRecord model objects in a form
  • Parsing form data - how Rails parses incoming form data

Input field helpers

    f.error_messages_for
    f.check_box :terms, { :class => 'check' }, "yes", "no"
    f.file_field :image
    f.hidden_field :id
    f.label :customer, "Text for label"
    f.password_field :password
    f.radio_button :language, "French"
    f.text_area :comment, :size => "20x30", :disabled => "disabled"
    f.text_field :age, :size => "20", :class => "age_box"



 

 

> 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