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
5
votes
3 answers

How to use :selected with grouped_collection_select

Is it possible to somehow use the :selected option that you'd use on a normal select view helper with the grouped_collection_select function? I'd like to set the value that gets pre-selected in my list. I've tried passing in :selected as an option…
4
votes
1 answer

How to return elements with the most recent date in MongoDB

On MongoDB, how can I select elements with the most recent date from this list : [{ "_id" : ObjectId("5c5064f39d0c4b52cf6d1d55"), "Date" : "12-09-2018", "Type" : "A", "Value" : 73650.14 }, { "_id" : ObjectId("5c5064f39d0c4b52cf6d1d15"), "Date" :…
4
votes
5 answers

Grouped Collection Select Alphabetical Order Rails

I finally figured out how to implement Dynamic Select menus using this tutorial. Everything works, But how does one organize the Cities in the Dropdown by Name.... Below is all of the code I've written. (Please let me know if you need any further…
Serge Pedroza
  • 2,160
  • 3
  • 28
  • 41
2
votes
2 answers

Collection_Select display multiple fields in dropdown

I'm using collection_select which connects to my Airports model. Claim belongs_to :departure_airport, :class_name => 'Airport', :foreign_key => 'd_airport_id' belongs_to :arrival_airport, :class_name => 'Airport', :foreign_key =>…
Dearg
  • 47
  • 10
2
votes
1 answer

how to obtain a subset of records for a grouped_collection_select in Rails

I'm trying to obtain a subset of records for a grouped_collection_select, in the schema I have a Brand and a Model, and we handle different lines of products, when we request a product, we specify the line that we are going to request, so, we can…
2
votes
1 answer

adding class to grouped_options_for_select in Rails 4 form

I can't seem to get the class on this select to work. The grouped collection works...but not the class: = f.select :topic_id, grouped_options_for_select([['News', @topics.news.order(title: :asc).collect {|v| [ v.title, v.id ] }], …
2
votes
1 answer

Grouped Collection Select on Single Model/Table?

Is it possible to do a grouped_collection_select on a single model? Most examples I've seen use two models.For example this Railscast: http://railscasts.com/episodes/88-dynamic-select-menus-revised I have a Venue model with fields for venue name and…
Raoot
  • 1,751
  • 1
  • 25
  • 51
1
vote
0 answers

Simple form with collection select returning a hash

I am trying to get a dropdown list of projects organized according to the owner name. For doing this I am using SimpleForm and the grouped_select method. The issue is that for now it is a hash that is send back to the dropdown list and not the name…
1
vote
1 answer

grouped_collection_select, Devise and Rails 5.0 custom registration issue

I'm having having some issues with custom Devise registration in Rails 5. I have 3 models with the following AR associations User (Devise) belongs_to :chapter Chapter belongs_to :country has_many :users Country has_many :chapters I created a…
1
vote
1 answer

how to update observable collection group

I have implemented group observable collection like below. Grouped Property private ObservableCollection> _groupedList = null; public ObservableCollection> GroupedList { get { return…
1
vote
2 answers

d3 grouped bar chart highlight group on mouseover

Solved: jsfiddle Issue #1: Have a grouped bar chart. I'd like the group to highlight if any bars in the group are moused-over. Currently on mouseover sets all rects with class 'bar' to opacity 0.5 and then the specific rect to opacity 1. But how can…
Shane G
  • 3,129
  • 10
  • 43
  • 85
1
vote
1 answer

Collection Group by using same table's column

I have record in database like below Table :Role ================ id: sub_category: main_category: 1 john student 2 somaina student 3 sharif teacher 4 Imran student 5…
1
vote
1 answer

Rails selection list issue

I have a model Member that has a new creation form. The form allows users to assign a department and position for each member to be a part of. The positions are relative to the department. In a separate part of the app, users can create…
Dan Brookwell
  • 341
  • 2
  • 12
1
vote
1 answer

grouped_collection_select with different option_key_methods

I'm using grouped_collection_select with polymorphic associations to assign either a company or person to a task. The issue is that people have a first name and a last name, while a company just has a name. I would like to use a concatenation of…
1
vote
0 answers

RubyOnRails - option_groups_from_collection_for_select and translation of content

I have a collection, I am showing to the user. But I need to I18n.translate the :key into a readable text from my de.yml. competences: key: compkey001: "Werbung / 360" compkey001subkey002: "Klassische Werbung / ATL" compkey002:…
Cokiehh
  • 63
  • 1
  • 11
1
2 3