I have a model for "Location" which has a title, description, and type. The type can be a "Bar", "Restaurant", etc. I want to have a select box in my view with the various options with multiple selections available.
How would i go about parsing the select box in my controller and storing it in the database?
If you want to use type as select box in a Location form, you could put the possible types inside the Location class.
class Location < ActiveRecord::Base
attr_accessible :type
TYPES = ["Bar", "Restaurant"]
end
View
<%= f.select(:type, options_for_select(Location::TYPES.each {|y| y.capitalize! } ), { :prompt => "Select Type" }) %>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.