ruby on rails - Grouped Collection Select on Single Model/Table? -
is possible grouped_collection_select on single model? examples i've seen use 2 models.for example railscast: http://railscasts.com/episodes/88-dynamic-select-menus-revised
i have venue model fields venue name , town (amongst other things). venue select huge , i'd group town. need move towns separate model?
where store towns now? better solution anyway have towns in model, depends on other things, if thing towns data change on time. can add grouped select without new model. try this:
<% form_for @venue |f| %> <%= f.select :town, grouped_options_for_select(@towns) %> ... however @towns should , 2-dimensional array this
[ ["group1", ["town1", "town2", "town3"] ], ["group2", ["town4", "town5", "town6"] ] ] you can see more here: http://api.rubyonrails.org/classes/actionview/helpers/formoptionshelper.html#method-i-grouped_options_for_select
otherwise if have example of data towns , current form, more :)
Comments
Post a Comment