4 Awesome Form Elements and How to Use Them

One of the most-used features in web development is the action of collecting data from the user. From a contact page to creating a Ticketfly account, we are constantly using forms across the web.

Thankfully, Rails recognizes the pain of creating endless label/text_field forms. Here is a list of some cool elements to help break up the tedium.

check_box_tag – choose a favorite director

<%= check_box_tag(:director_scorsese) %>
<%= label_tag(:director_scorsese, "Scorsese movies are the best") %>
<%= check_box_tag(:director_anderson) %>
<%= label_tag(:director_anderson, "Wes Anderson movies are the best") %>

radio_button_tag – choose an age group out of a list

<%= radio_button_tag(:city_in_oregon, "portland") %>
<%= label_tag(:city_in_oregon, "I live in Portland") %>
<%= radio_button_tag(:city_in_washington, "seattle") %>
<%= label_tag(:city_in_washington, "I live in Seattle") %>

date_field – choose a preferred date for a doctor’s appointment calendar

<%= date_field(:date) %>

collection_select – choose an origin city for fancy oranges

    <%= f.label :source %>
    <%= f.collection_select(:source_id, Source.all, :id, :city) %>

Resources: