Forum: Ruby on Rails DRYing up form tags

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Shilo A. (Guest)
on 2009-01-26 12:25
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.
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 ->
http://onrails.org/articles/2008/06/13/advanced-ra...
-
Maurício Linhares
http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/
(en)



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