Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7028555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:24:13+00:00 2026-05-28T00:24:13+00:00

I have a grouped_collection_select for a branch field, in combination with a sector field.

  • 0

I have a “grouped_collection_select” for a “branch” field, in combination with a “sector” field. Sector has_many branches and branch belongs_to sector:

<%= f.grouped_collection_select(:branch, current_user.company.sectors.order(:sector), :branches, :sector, :id, :branch, include_blank: true) %>

This works, but the “:branches” shows all branches and should only show the branches of the current_user.company, just like the sectord. But when I change “:branches” into “current_user.company.branches.order(:branch)”, I get an error:

(eval):1: syntax error, unexpected $end group.#<ActiveRecord

What am I doing wrong here? Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:24:14+00:00Added an answer on May 28, 2026 at 12:24 am

    For clarity (and semantics) set that collection in your controller to use in your view:

     @sectors = current_user.company.sectors.order(:sector)
    

    …or if you want to limit the branches that are showing for each sector by user, you’d probably want to build the collection based on the user’s branches. One example:

     @sectors = current_user.company.branches.collect{|b| b.sector}.uniq
    

    Then assuming you want to set the branch_id AND a sector has a name attribute AND the branch has a name attribute, this should work:

     <%= f.grouped_collection_select(:branch_id, @sectors, :branches, :name, :id, :name, :include_blank=>true)
    
     #:branch_id is the attribute you will be setting on the form_builder's object.
     #@sectors is the collection of objects for the groups.
     #:branches is the method that will be called on each sector object.
     #:name is the method that will be called on each sector object to label the group.
     #:id is the method that will be called on each branch to set the option's value.
     #:name is the method that will be called on each branch to set the option's label. 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following List: 1: true; 2: false; 2: true; 3: false; 3:
I have Grouped Table View in which I want to display Contact details. But
I have a grouped UITableView which displays a number of cells, which includes both
I have a grouped table with 3 sections, each section with a title. The
I have a grouped UITableView where not all sections may be displayed at once,
I have a grouped UITableView with many sections, however, I want to iterate through
I have table View with grouped style with three sections. Get information from dictionary
I have a series of grouped values that follow a specific format and would
I have created a TableView(Grouped Table View). And I can list the items in
I have multiple input text fields grouped in divs: <div class=container0> <input class=containerItem0 name=containerItem[0][0]

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.