# Map select value or other to same attribute

**URL:** <https://www.ruby-forum.com/t/map-select-value-or-other-to-same-attribute/96425>\
**Category:** Rails\
**Created:** [January 24, 2006, 5:25am UTC](https://www.ruby-forum.com/t/map-select-value-or-other-to-same-attribute/96425 "2006-01-24T05:25:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jason\_cartwright](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ecd19e/32.png) [@jason\_cartwright](https://www.ruby-forum.com/u/jason_cartwright)\
**Post date:** [January 24, 2006, 5:25am UTC](https://www.ruby-forum.com/t/map-select-value-or-other-to-same-attribute/96425/1 "2006-01-24T05:25:31Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jason\_cartwright](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ecd19e/32.png) [@jason\_cartwright](https://www.ruby-forum.com/u/jason_cartwright)\
**Post date:** [January 24, 2006, 6:29am UTC](https://www.ruby-forum.com/t/map-select-value-or-other-to-same-attribute/96425/2 "2006-01-24T06:29:13Z")

</div>

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 S.

---

<div class="post-metadata">

**Author:** ![jason\_cartwright](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ecd19e/32.png) [@jason\_cartwright](https://www.ruby-forum.com/u/jason_cartwright)\
**Post date:** [January 25, 2006, 10:51pm UTC](https://www.ruby-forum.com/t/map-select-value-or-other-to-same-attribute/96425/3 "2006-01-25T22:51:09Z")

</div>

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.
