Rendering a selection box for 50 states I was creating a Rails form where users have to enter their state. I ended up creating a select tag which is really, really ugly.

I'd like to think there's a better way of writing this. 

&lt;p&gt;
        &lt;%= f.label :state, "State:*" %&gt;&lt;/br&gt;
          &lt;%= f.select(:state, [['AL', 'AL'], ['AK', 'AK'], ['AZ', 'AZ'], ['AR', 'AR'], ['CA', 'CA'], ['CO', 'CO'], ['CT', 'CT'], ['DC', 'DC'], ['DE', 'DE'],
          ['FL', 'FL'], ['GA', 'GA'], ['HI', 'HI'], ['ID', 'ID'], ['IL', 'IL'], ['IN', 'IN'], ['IA', 'IA'], ['KS', 'KS'], ['KY', 'KY'], ['LA', 'LA'], ['ME', 'ME'],
          ['MD', 'MD'], ['MA', 'MA'], ['MI', 'MI'], ['MN', 'MN'], ['MS', 'MS'], ['MO', 'MO'], ['MT', 'MT'], ['NE', 'NE'], ['NV', 'NV'], ['NH', 'NH'], ['NJ', 'NJ'],
          ['NM', 'NM'], ['NC', 'NC'], ['ND', 'ND'], ['OH', 'OH'], ['OK', 'OK'], ['OR', 'OR'], ['PA', 'PA'], ['RI', 'RI'], ['SC', 'SC'], ['SD', 'SD'], ['TN', 'TN'],
          ['TX', 'TX'], ['UT', 'UT'], ['VT', 'VT'], ['VA', 'VA'], ['WA', 'WA'], ['WI', 'WI'], ['WV', 'WV'], ['WY', 'WY']]) %&gt;
        &lt;/p&gt;
you should move the states list outside of view, i.e. to model class.

class User &lt; ActiveRecord::Base
  STATES = ['AL', 'AK', 'ID']
end


then in view:

&lt;%= f.label(:state, "State:*") %&gt;&lt;/br&gt;
&lt;%= f.select(:state, User::STATES) %&gt;&lt;/br&gt;


This will allow you to reuse states collection anywhere across the application and add easily validate if user hasn't modified the form manually.

Keeping states in User model is not necessary the best option but it's outside of this question scope