I have a three tables Plan, Channel and ChannelCategory. While creating a new Plan I want to select multiple channel_categories and based on that I want to select multiple channels. Please provide me the solution.
1 Answer
For multiple select you could do something like this
<%= f.select(:channel_category, [['Sports', 'sports'],
['Entertainment', 'entertainment'],
['Music', 'music']
],{ :prompt => "Please select"},
{ :multiple => true, :size => 3 }) %>
Edit:
then for channels you'll also need multiple select
<%= f.select(:channels, [['Channel1', 'ch1'],
['Channel1', 'ch2'],
['Channel1', 'ch3']
],{ :prompt => "Please select"},
{ :multiple => true, :size => 3 }) %>
And if you need channels after selecting channel_categories maybe you could try with conditional validations.
I had similar problem so I solved it with conditional validations.
6 Comments
Prafull Purwar
I do not get you why I need nested form.
Prafull Purwar
I am creating a new Plan in which I can select multiple channel categories as Sports, Entertainment, Music etc. and whichever are selected on that basis I want to select multiple channels based on above selected channel categories.
Prafull Purwar
Can you please guide me as it is working for single channel category.
Prafull Purwar
But I want to get channels for multiple channel categories. Hope now you get my requirement.
Prafull Purwar
This is I have done but on selecting channel category I want channels of that channel category to be come in another drop-down and I can select multiple channels in that second drop-down.
|