Hi! If i have something like this used to create select tag: options = [["Dollar", "$"], ["Kroner", "DKK"]] and later read value from the database and get "DKK", what is the easiest way to get "Kroner" value? -- Posted via http://www.ruby-forum.com/.
Mark Reginald James
2006-Mar-08 23:52 UTC
[Rails] Re: question about options_for_select array
szymek wrote:> If i have something like this used to create select tag: > > options = [["Dollar", "$"], ["Kroner", "DKK"]] > > and later read value from the database and get "DKK", what is the > easiest way to get "Kroner" value?If you don''t want to go all the way and create a currencies table in the database, add a currency.rb file in the models directory, containing: class Currency OPTIONS = [["Dollar", "$"], ["Kroner", "DKK"]] def self.symbol_to_name( symbol ) OPTIONS.rassoc(symbol).first end end Use like: options_for_select( Currency::OPTIONS ) and Currency.symbol_to_name( @amount.currency_symbol ) -- We develop, watch us RoR, in numbers too big to ignore.