# Attribute name selected in form

**URL:** <https://www.ruby-forum.com/t/attribute-name-selected-in-form/190566>\
**Category:** Rails\
**Created:** [June 22, 2010, 9:21pm UTC](https://www.ruby-forum.com/t/attribute-name-selected-in-form/190566 "2010-06-22T21:21:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mlle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/eada6e/32.png) [@Mlle](https://www.ruby-forum.com/u/Mlle)\
**Post date:** [June 22, 2010, 9:21pm UTC](https://www.ruby-forum.com/t/attribute-name-selected-in-form/190566/1 "2010-06-22T21:21:42Z")

</div>

Hello,

I have a form to add terms to a thesaurus table.  
I have a drop-down list for the user to select the language (fr, en,  
es,), and then a text box to write a term with a code. I want to set  
the @thesaurus[whichever language was selected] = term.

How can I say @thesaurus[‘fr’] = term, where ‘fr’ was the selected  
language in the select box?

Parameters: { “lang”=\>“fr”, “thesterm”=\>{“term”=\>“pigment”=\>""},  
“commit”=\>“submit”}

Thesterm Create (0.4ms) INSERT INTO `thesterms` (`en`, `fr`, `it`,  
`fi`, `sr`, `code`, `refcount`) VALUES(’’, ‘pigment’, ‘’, ‘’, ‘’,  
NULL, NULL)

---

<div class="post-metadata">

**Author:** ![Mlle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/eada6e/32.png) [@Mlle](https://www.ruby-forum.com/u/Mlle)\
**Post date:** [June 23, 2010, 7:11pm UTC](https://www.ruby-forum.com/t/attribute-name-selected-in-form/190566/2 "2010-06-23T19:11:56Z")

</div>

Hi,

I suppose the best way to do this would be to create a row for each word  
having a column for lang and a column for term.

If you want to do it the way you describe, you could do it like this:

With validation:  
@thesaurus.update\_attributes params[:lang] =\> term

Without validation:  
@thesaurus.update\_attribute params[:lang], term

Without updating:  
@thesaurus.attributes = { params[:lang] =\> term }

Hope this helps.

/Lasse

2010/6/22 Mlle [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Mlle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/eada6e/32.png) [@Mlle](https://www.ruby-forum.com/u/Mlle)\
**Post date:** [June 23, 2010, 7:27pm UTC](https://www.ruby-forum.com/t/attribute-name-selected-in-form/190566/3 "2010-06-23T19:27:45Z")

</div>

Or you could make the [] method you mentioned. In your model:

def []=(lang, term)  
self.attributes = { lang =\> term }  
end

Then you can call it like you wanted:

@thesaurus[‘fr’] = “Bonjour”

/Lasse

2010/6/23 Lasse B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
