jason cartwright
2006-Jan-24 04:22 UTC
[Rails] Map select value or other to same attribute
I want to map a select control and a text field to a single attribute, where the end user can either select an option, or select "other" and then fill in the text field. However, I want these values to map to the same underlying attribute. Any suggestions?
class MyClass def before_save if MyClass.select_box_value == ''other'' and not params[:text_field_other].empty? MyClass.select_box_value = params[:other_selection] end end end This may not be totally accurate, but it''ll get you pointed in the right direction. NOTE: The text field will need to be output using text_field_tag or hard-coded on the page. IT DOES NOT represent part of your ActiveRecord class. Cheers, Bob Silva> -----Original Message----- > From: rails-bounces@lists.rubyonrails.org [mailto:rails- > bounces@lists.rubyonrails.org] On Behalf Of jason cartwright > Sent: Monday, January 23, 2006 8:22 PM > To: rails@lists.rubyonrails.org > Subject: [Rails] Map select value or other to same attribute > > I want to map a select control and a text field to a single attribute, > where the > end user can either select an option, or select "other" and then fill in > the > text field. However, I want these values to map to the same underlying > attribute. > > Any suggestions? > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Jason Cartwright
2006-Jan-25 21:50 UTC
[Rails] Re: Map select value or other to same attribute
Thanks Bob! I''ll give that a try and see what I can do. Sometimes I just get lazy, or I want to understand "the rails way", and like to toss these issues out to the community. Thanks for the suggestion and I''ll get back with my success or questions shortly.