Rails: A Brief Note on Form Helper Tags

April 16, 2010

Just a brief note on Rails form helper tags, since I haven't seen it explicitly stated anywhere.

When creating a Ruby on Rails form ( form_for(@survey) do |f| ):

<%= radio_button_tag "question2", 1 %> <%= f.radio_button "question2", 1 %>

Both create a radio button tethered to the variable question2, representing its having a value of 1.

The difference is that radio_button_tag will place the hash "question2"=>"1" in the general parameter hash. f.radio_button will place that same hash within the survey hash, itself within the general parameter hash.