[Rails] Using store values from drop down list
Hi,
I was trying to understand stored values vs display values.
# model code
CLUB_TYPES = [
# Displayed stored in db
[ "Public" , "pub" ],
[ "Village" , "vil" ],
[ "Private" , "pvt" ]
]
validates_inclusion_of :club_type, :in =>
CLUB_TYPES.map {|disp, value| value}
#view code
<%= f.select :club_type, Club::CLUB_TYPES, :prompt => "Select a Club
Type" %>
This works fine for getting data into the database.
My question: Is there a helper to get the display value back from the
database? If not, could somebody show me how to correct the following
to get the display value rather than the stored value.
<b>Club Type:</b>
<%= @club.club_type %>
Thanks
--
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-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home