Question about options_for_select array


#1

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?


#2

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.