Rails – Selection List on Form Builder

Now i have the country hash ready which is all we need to build a selection list in view.
Rails – Retrieve a Hash from Model

We can create a selection list using the f.select() method. The following view is an example.

  # Get the countries hash for selection list
  @countries = Country.hashify
  <p><%= f.label :country %><br />
  <%= f.select(:country, @countries) %></p>


Resulted view.


Done =)

Reference: Rails Guides – Rails Form helpers

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.