Questions tagged [collection-select]
143 questions
0
votes
1 answer
Rails 4.2 - how to build a has_many, through: association with collection_select
I'm currently using Rails 4.2 with these models:
class User < ActiveRecord::Base
has_many :user_accessories, dependent: :destroy
accepts_nested_attributes_for :user_accessories,
reject_if: :all_blank,
allow_destroy: true
has_many…

s_dolan
- 1,196
- 1
- 9
- 21
0
votes
0 answers
Ruby on Rails - Collection_select, option class
is it possible to pass a model-attribute of the collection to the select-options class?
<%= f.collection_select :bank_connection_id, BankConnection.all, :id, :bank_name, {:class => ? } %>
The Questmark shows where i wanted to use a attribute of the…

Tobias Münch
- 829
- 4
- 13
0
votes
1 answer
Filter index with has_scope gem and collection_select
I've got a two models: Business and Category. In my business#index view, all Business names are displayed in a table, along with their associated Category. I'm using the has_scope gem and added two scopes to my Business model: :by_category and…

K.C. Barrett
- 152
- 1
- 9
0
votes
2 answers
rails has_many through create multiple join records with collection_select
I'm pretty new to rails and trying to get three models to work together with a has_many through relationship, alternate class names on the join model, and a collection_select form to add records to the join model. The three models are below. I have…

Luke Wilcox
- 5
- 1
- 3
0
votes
1 answer
Rails 4: How can I get the value[id] of a selected item with collection_select in my form
In my controller I would like to do the following:
class SubsController < ApplicationController
def push_sub
@sub = Sub.find(params[:id])
@food = Food.find("ID of food selected from collection_select") => see my form down below
…

Antoine
- 559
- 8
- 21
0
votes
1 answer
Sort rails collection_select dropdown field by foreign attribute
I've got a collection_select and I want to sort it.
usually no problem, just pass a collection.order(name DESC) or whatever to do that into the collection_select's collection field.
Unfortunately, my sort criteria is a foreign attribute, something…

McSlow
- 69
- 6
0
votes
1 answer
collection_select with a dynamic value
I am a newbie with ruby on rails and I need to add a collection_select that display the quantity of book to sell from 1 to the quantity saved in the database
for example I have 4 examplaries of a certain book, so i need to display a collecion select…

rota90
- 249
- 1
- 4
- 17
0
votes
1 answer
Matching up collection_select output with strong parameters
In rails console & using the models below, I connected grades K, 1, and 2 to the school whose Edit form has this select field:
As you can see, that association correctly selects the 3 items in the field, but if I click to select/deselect grades,…

clozach
- 5,118
- 5
- 41
- 54
0
votes
1 answer
Dropdown depending on another collection_select rubyonrails
Guys that is my code thing is I want to select a parent subject and upon selection I need to use that selected subject to list the topics within it in the parent field how can i do that?
…

Ayman Salah
- 1,039
- 14
- 35
0
votes
1 answer
Call function for Rails colleciton_select
I need to better manipulate a strong for a collection_select. I only see how to call a function on the object, but I need to do some more manipulation that the object won't know about. Is there a way to do…

MechDog
- 508
- 7
- 18
0
votes
1 answer
Form using collection_select, edit action works entirely but create does not
I am using following form and controller. If I create a new notification everything gets saved except the campus_id.
It seems to give the wrong campus parameter although I select a different one from the dropdown. If I edit the same entry afterwards…

Christoph
- 1,347
- 2
- 19
- 36
0
votes
0 answers
Rails collection_select NoMethodError
In my view I have a collection_select. I want it to prompt the user to select if the session variable is set to 0. The else works fine but if the condition is 0 then it is telling me that there is no method 'id'.
- if session[:ptype_id] == 0
=…

Beengie
- 1,588
- 4
- 18
- 36
0
votes
3 answers
Rails Newbie: Collection Select & Controller Logic
I've read many related questions here, but I still don't understand how to do the following:
I have a "Country" model and I'd like to create a select form that will allow users to select any of the existing countries in the model, and be redirected…

kongzi
- 5
- 3
0
votes
1 answer
How to use collection_select in rails 4 from a model module?
I am trying to use collection_select tag for the default _form.html.erb using a concern/module, I need to set a hash including some department names.
Here is my app/models/concerns/SetDepartment.rb
module Set_Department
extend…

They_Call_Me_Joe
- 194
- 1
- 11
0
votes
0 answers
RoR Many to Many relationship and form
I'm stuck with this issue.
The RoR doc about this topic is really awful.
I don't understand how collection_select works.
I have two models : Skills and Projects.
A Project have many skills and a skill have many projects.
So here are my schemas…
user1746732