Ask A Question

Notifications

You’re not receiving notifications from this thread.

grouped_options_for_select --- include a select all

Amanda asked in Rails

Hi,

I have Categories and CategoryType. A Category has_many CategoryTypes. In my form, I am using grouped_options_for_select to display the different category types for a category.

Form:

 <%= f.select :category_type_id,  grouped_options_for_select(@grouped_category_type_options),  {'data-width' => "100%", include_blank: 'Categories'}, {:class => "form-control border-0 shadow-0 transparent-form"} %>

Being set in the controller:

  @grouped_category_type_options = CategoryType.includes(:category).inject({}) do |options, type|
    (options[type.category.name] ||= []) << [type.name, type.id]
    options

What I want to know is that is there a way for me to also include an "all" option for the user to select "all" the category types for a set category. For example, for the category of "Hotels," the category types are "Hostel", "B&B", and "Motel". I want to also include an "All" option that will allow me to filter for all hotels regardless of the set category type.

Can anyone help me with this or point me in the right direction?

Thanks!

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 85,376+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.