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?
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?
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.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs