Forum: Ruby on Rails Map select value or other to same attribute

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.
Abdf9626d4bdacbe16703056e37215d5?d=identicon&s=25 jason cartwright (Guest)
on 2006-01-24 05:25
(Received via mailing list)
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?
Af93ba6b6b59f22a8f37e8de5702ef98?d=identicon&s=25 Bob Silva (Guest)
on 2006-01-24 06:29
(Received via mailing list)
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
Abdf9626d4bdacbe16703056e37215d5?d=identicon&s=25 Jason Cartwright (Guest)
on 2006-01-25 22:51
(Received via mailing list)
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.
This topic is locked and can not be replied to.