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 comment

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