Monday, July 11, 2011

[Rails] how to create dropdown from a hash in rails 3

In rails 3, how to create a Dropdown from hash

I have following code in my User class

class User
... other codes
key :gender, Integer # i use mongo db

class << self
def genders() # not sure how to define static value, so do in
this way
genders = {
'1' => 'Male',
'2' => 'Female',
'3' => 'Secret'
}
end
end

end

In the user form, i am trying to create a gender dropdown list
<%= f.collection_select nil, :gender, User.genders, :key, :value %>

but it complain
undefined method `merge' for :value:Symbol

So what is the proper way to create the dropdown?

Thanks

--
View this message in context: http://old.nabble.com/how-to-create-dropdown-from-a-hash-in-rails-3-tp32043403p32043403.html
Sent from the RubyOnRails Users mailing list archive at Nabble.com.

--
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


Real Estate