Questions tagged [grouped-collection-select]

In Ruby on Rails, grouped collection select returns

From the docs

Example object structure for use with this method:

class Continent < ActiveRecord::Base
  has_many :countries
  # attribs: id, name
end
class Country < ActiveRecord::Base
  belongs_to :continent
  # attribs: id, name, continent_id
end
class City < ActiveRecord::Base
  belongs_to :country
  # attribs: id, name, country_id
end

Sample usage:

grouped_collection_select(:city, :country_id, @continents, :countries, :name, :id, :name)

Possible output:

<select name="city[country_id]">
  <optgroup label="Africa">
    <option value="1">South Africa</option>
    <option value="3">Somalia</option>
  </optgroup>
  <optgroup label="Europe">
    <option value="7" selected="selected">Denmark</option>
    <option value="2">Ireland</option>
  </optgroup>
</select>
43 questions
1
vote
1 answer

I have a conflict with a dependent select

I have some issue with grouped_collection_select in rails 4, so I need your help. I have this models: class Event < ActiveRecord::Base has_many :appointments belongs_to :user scope :evento_sin, -> { where(available: "1") } end class User <…
1
vote
1 answer

Collection Select undefined method in Rails 4

I have a form that requires pulling all of the objects in the database into a select field. I've reviewed other SO questions about collection_select and can't seem to figure out why I'm getting an undefined method error. # Loan Application…
1
vote
1 answer

Grouping a Rails collection_select by a field's value

I would like to have the following collection_select be grouped by State, which is a field on Tuning that is either Public or Private. Is this possible? In the view: <%= collection_select :tunings, :tuning, @fretboard_tuning_options, :id, :name, {},…
jackerman09
  • 2,492
  • 5
  • 29
  • 46
1
vote
1 answer

implement grouped_collection_select not working

I want dropdown in User sign up form which will set the user role which belongs to a department. Here is are models class Department < ActiveRecord::Base has_many :roles end class Role < ActiveRecord::Base belongs_to :department has_many…
1
vote
1 answer

Rails collection_select not creating records - nil id

I am following the first part of Ryan Bate's episode #285. Not sure why it is not working. Here is the code: models: class Comic < ActiveRecord::Base has_many :comics_genres has_many :genres, through: :comics_genres end class ComicsGenre…
Jayway
  • 95
  • 2
  • 8
1
vote
2 answers

expected, got String

I'm still pretty new to Rails so I could be missing some pretty major here and that's easy to fix or maybe a piece that I just haven't studied yet. I'm creating a tour in regular form. The form has many fields but the one in question and where I'm…
Michael
  • 589
  • 2
  • 11
  • 26
1
vote
1 answer

How to use grouped collection select to show multiple selection?

I'm using the following code to display a tree view selection box of categories: grouped_collection_select(:logic, :logic_id, Logic.top_level, :child, :name, :id, :name, :include_blank => true) How can I change it to allow multiple selection? Also,…
SSP
  • 2,650
  • 5
  • 31
  • 49
1
vote
0 answers

How to implement a dynamic grouped_collection_select where users can "Add New"?

In a Rails 3.2 app I have a pair of dynamic select fields. The typical example of this is a country select which, on change, will filter the options of a state select. This is working perfectly. But what if I need to allow users to add a new state…
Andy Harvey
  • 12,333
  • 17
  • 93
  • 185
0
votes
1 answer

How do you upload all items in a model in Rails?

Say I have a form for entering subject marks (separate model) and I want to enter marks for students from a specific classroom from a select box. How do I upload all students based on the classroom I select and have them line up next to marks…
Sawo Cliff
  • 2,888
  • 1
  • 17
  • 21
0
votes
1 answer

grouped_options_for_select in rails 4

I done grouped_options_for_select. I want a prompt. If there no options to select under the group, there should not any space. I try with the following code. controller: @grouped_options = @subjects.inject({}) do |options, product| …
Kannamma
  • 1
  • 2
0
votes
1 answer

How can I add an ID to an option inside a grouped_collection_select

I currently have a Multi Select Box that groups Rooms with their respective Building. Everything works great, except, I would like to add an ID to each option. How can I do this? FORM
<%=…
0
votes
1 answer

Rails grouped_collection_select with 3 models

I'm attempting to follow the Rails Docs and Railscast#88 but with 3 models. The page will have 3 drop down boxes for State, County, & City. I have State > County working with JQuery. But when trying to build the grouped_collecion_select for the…
David
  • 85
  • 1
  • 7
0
votes
2 answers

RoR - dynamic dropdown with checkboxes

I am looking to implement a dynamic dropdown with checkboxes in it so the sender of a message can choose multiple receivers. Currently I just have a list of recipients under the message textarea. _recipients.html.erb: <% @recipients.each do |user|…
Co2
  • 343
  • 1
  • 14
0
votes
1 answer

rails collection_select params

So I am trying to filter some data based on a collection_select drop down box. I can successfully use a text_field_tag to filter the data, so I assume my filter is working fine, but I can't get the collection_select to do the same? If I type a 1…
0
votes
1 answer

Rails show string not ID in index

I have the following form where a user selects a department from a list of database entries on the activity centers page. I am trying to display the department string (:department) instead of the department ID. I tried…