Forum: Ruby on Rails Retrieving Global Arrays

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
78afdba6236b562b3c0f582d69cd161a?d=identicon&s=25 Sav (Guest)
on 2009-01-21 20:07
(Received via mailing list)
I inherited an app that created STATES & COUNTRIES as global hashes in
config/environment.rb

STATES = {}
STATES[:AL] = 'Alabama'
STATES[:AK] = 'Alaska'
STATES[:AZ] = 'Arizona'
...

I'm able to render the name correctly like this...
<%= STATES[:AK] %>

But what is the syntax to call that dynamically?  This does not
work...
<%= STATES[location.state] %>

Thanks, I'm stumped on this noob issue.
A91bd6cef23eb3516245a092e196c4da?d=identicon&s=25 Maurício Linhares (mauricio)
on 2009-01-21 20:10
(Received via mailing list)
<%= STATES[location.state.to_sym] %> ?

-
Maurício Linhares
http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/
(en)
This topic is locked and can not be replied to.