# Custom helpers for list of options?

**URL:** <https://www.ruby-forum.com/t/custom-helpers-for-list-of-options/116444>\
**Category:** Rails\
**Created:** [October 5, 2007, 4:25pm UTC](https://www.ruby-forum.com/t/custom-helpers-for-list-of-options/116444 "2007-10-05T16:25:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pedro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/919ad9/32.png) [@pedro](https://www.ruby-forum.com/u/pedro)\
**Post date:** [October 5, 2007, 4:25pm UTC](https://www.ruby-forum.com/t/custom-helpers-for-list-of-options/116444/1 "2007-10-05T16:25:25Z")

</div>

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  
way?

Thanks.

For example : [Parked at Loopia](http://pastie.caboo.se/104092)

# = 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  
end

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

# = Schema

# country :string

# city :string

# state :string

# profession :string

# category :string

# …

class User \< ActiveRecord::Base  
end

class ApplicationHelper  
def city\_select (…)  
end

# …

# …

end

## –

Pedro Del G.

Email : removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![pedro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/919ad9/32.png) [@pedro](https://www.ruby-forum.com/u/pedro)\
**Post date:** [October 5, 2007, 4:31pm UTC](https://www.ruby-forum.com/t/custom-helpers-for-list-of-options/116444/2 "2007-10-05T16:31:15Z")

</div>

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  
helper:

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

Then from my view:

\<%= select ‘document’, ‘language\_id’, language\_options %\>

Hope this helps.
