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 Bunk <lasseb...@gmail.com> > 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 <emsto...@gmail.com> > > 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) >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Talk" group. >> To post to this group, send email to rubyonrails-t...@googlegroups.com. >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscr...@googlegroups.com<rubyonrails-talk%2bunsubscr...@googlegroups.com> >> . >> For more options, visit this group at >> http://groups.google.com/group/rubyonrails-talk?hl=en. >> >> > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.