Ask A Question


You’re not receiving notifications from this thread.

grouped_options_for_select --- include a select all

Amanda asked in Rails


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.


 <%= :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[] ||= []) << [,]

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?


Join the discussion
Create an account Log in

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

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

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

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

    © 2023 GoRails, LLC. All rights reserved.