Forum: Ruby on Rails DRYing up form tags

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Shilo A. (Guest)
on 2009-01-26 12:25

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

<%= f.names_select :state_id, State %>

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

<%= :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.
Maurício L. (Guest)
on 2009-01-26 14:20
(Received via mailing list)
Instead of writting custom tags, you could write a custom form builder
with methods for those fields ->
Maurício Linhares (pt-br) |

On Mon, Jan 26, 2009 at 7:25 AM, Shilo A.
This topic is locked and can not be replied to.