Custom helpers for list of options?

Hi all,

I have a model that “belongs_to” many other models, many of those
models are just list of names, like country, state, city, profession
… I read about the country_select helper.

Is better to have all those tables or use custom helpers? what the rails


For example :

= Schema

country_id integer

city_id integer

state_id integer

profession_id integer

category_id integer

class User < ActiveRecord::Base
belongs_to :country, :city, :state
belongs_to :profession, :category, :subcategory

=========== VS

= Schema

country :string

city :string

state :string

profession :string

category :string

class User < ActiveRecord::Base

class ApplicationHelper
def city_select (…)


Pedro Del G.

Email : [email protected]

I use tables and then just have helpers that build the arrays for
the select_options for the view.

For example, I have a table for languages and I have this in my

def language_options
Language.find(:all, :order => “language”).collect {|l| [ l.language, ]}

Then from my view:

<%= select ‘document’, ‘language_id’, language_options %>

Hope this helps.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs