# DRYing up form tags

**URL:** <https://www.ruby-forum.com/t/drying-up-form-tags/158641>\
**Category:** Rails\
**Created:** [January 26, 2009, 11:25am UTC](https://www.ruby-forum.com/t/drying-up-form-tags/158641 "2009-01-26T11:25:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gte351s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/5f9b8f/32.png) [@gte351s](https://www.ruby-forum.com/u/gte351s)\
**Post date:** [January 26, 2009, 11:25am UTC](https://www.ruby-forum.com/t/drying-up-form-tags/158641/1 "2009-01-26T11:25:47Z")

</div>

Hi,

I find that I have the following appear a lot inside forms in my app:

\<% names = SomeAssociatedModel.find(:all, :order =\> ‘name’)  
\<%= f.collection\_select :some\_id, names, :id, :name %\>

Which is basically a select list of names vs. id. I use it when I relate  
between associated models (with has\_many and belongs\_to). I would like  
to write a custom tag for it, something like:

\<%= f.names\_select :some\_id, object\_to\_select\_from %\> or similar. This  
way, I could use it when, say, editing cities that are associated with  
states:

\<%= f.names\_select :state\_id, State %\>

I also have a select that’s yes/no:

\<%= f.select :is\_active, [[‘yes’,true],[‘no’,false]] %\>

that I’d like to turn to:

\<%= f.yes\_no\_select :is\_active %\>

Any pointers will surely help - thanks.

---

<div class="post-metadata">

**Author:** ![gte351s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/5f9b8f/32.png) [@gte351s](https://www.ruby-forum.com/u/gte351s)\
**Post date:** [January 26, 2009, 1:20pm UTC](https://www.ruby-forum.com/t/drying-up-form-tags/158641/2 "2009-01-26T13:20:09Z")

</div>

## Instead of writting custom tags, you could write a custom form builder with methods for those fields → [http://onrails.org/articles/2008/06/13/advanced-rails-studio-custom-form-builder](http://onrails.org/articles/2008/06/13/advanced-rails-studio-custom-form-builder)

Maurício Linhares  
[http://alinhavado.wordpress.com/](http://alinhavado.wordpress.com/) (pt-br) | [http://blog.codevader.com/](http://blog.codevader.com/)  
(en)

On Mon, Jan 26, 2009 at 7:25 AM, Shilo A.
