Questions tagged [collection-select]
143 questions
2
votes
3 answers
rails 5 collection select
I am trying to make a collection_select that I get a drop down with the values of a field from another model. I got the following 2 models:
Documents:
class CreateDocuments < ActiveRecord::Migration[5.0]
def change
create_table :documents do…

aschmid
- 229
- 3
- 12
2
votes
1 answer
Rails 4 Dynamic Collection_Select
This seems to be a pretty popular question here, though I have yet to find a tutorial or thread that works for me. I have a two dropdown menus in a form, Team Type and User Role, where User Role is dependent on Team Type. The options for Team Type…

ncarroll
- 108
- 1
- 1
- 10
2
votes
3 answers
Best practice for custom text_method in collection_select?
I have Rails app with a use case to display prices in a collection_select dropdown box. For instance, names of products and their prices, or clients and amounts owing.
I well know it's bad MVC practice to simply include the relevant helpers to get…

Paulus
- 89
- 1
- 9
2
votes
1 answer
How can I search for a belongs_to using searchkick gem using collection_select?
I have two main models in my app, "Business" and "Category". I currently have a search text_field that works just fine, but I am also trying to implement the ability for users to search for Businesses that 'belongs_to' a certain category based on a…

ZMoodie
- 41
- 5
2
votes
1 answer
pass a parameter to collection_select's text_method in Rails
I have the following:
<%= collection_select 'product', 'id', @products, 'id', :description %>
- a list of products matched by the preceding keyword search.
And I'd like to use more specific description, which is built by model's method…

alex29
- 73
- 7
2
votes
1 answer
collection_select does not display text_method in rails 4
I am building a small project but it has taken an error.
I want to use a selection box to select my district (District model has 2 columns: id, name)
Here is my code
<%= f.select :district_id, options_for_select(District.all.collect {|p| [ p.name,…

Anh NGUYEN
- 101
- 1
- 6
2
votes
1 answer
has_many :through and collection_select rails form
I have tried all of the solutions to similar problems and haven't gotten this one figured out.
I have a has_many :through relationship between 'Clinician', and 'Patient' with a joined model 'CareGroupAssignment'. None of the methods I have tried so…

Skiapex
- 153
- 3
- 14
2
votes
2 answers
Rails: Multiple dropdown menus collection_select
Super Rails n00b here: Currently I have a form with the following code:
<%= f.collection_select :account_ids, @accounts, :id, :name, include_blank: true %>
and it currently works how I want it to but now I would like to have multiple drop down…

ckg61386
- 43
- 1
- 5
2
votes
2 answers
Rails has_many :through with collection_select form helper
I'm having issues with creating a form that will save my has_many :through associations. I've successfully saved by posting json, but the forms just won't work for me yet. The request params created by the form submit just won't work out. Any…

Thomas
- 368
- 1
- 7
- 19
2
votes
1 answer
Rails collection_select default select
In Rails 4 in view I have
<%= form_for @person do |f| %>
<%= f.collection_select :country_id, Country.order(:name), :id, :name, include_blank: "Select your country" %>
...
<% end %>
I'd like "Select your country" to be selected as default…

user2725109
- 2,286
- 4
- 27
- 46
2
votes
2 answers
Rails4 collection_select with data options
i want to reproduce the following select structure using FormHelper

Harsha M V
- 54,075
- 125
- 354
- 529
2
votes
3 answers
UJS, AJAX, Rails 4, form_for collection_select to pass value into method and return value back to form
I'm very new to Rails, and as such am having lots of of confusion when dealing with AJAX, UJS and Rails together. I've looked at railscast, several SO answers, tried #rubyonrails IRC channel on freenode.
Alas, I'm still stuck.
Anyway, here is my…

msadoon
- 143
- 2
- 11
1
vote
0 answers
Rails 7, many to many relationship, create action inserts duplicate values when using collection_select
I'm working on a Rails 7 app. I have a form for creating companies, each company can have multiple verticals. I'm using form.collection_select in the template to let users select one or many verticals. For some reason the create action tries to add…

Anders
- 2,903
- 7
- 58
- 114
1
vote
1 answer
What is a better way of collection_select for large datasets?
Currently, I have a model with 100+ records. I have a second model that has_one of the first model. In my form to create the second model, I'm using collection_select calling the first model. The user ends up having to scroll and look through each…

Unusualslim
- 81
- 7
1
vote
1 answer
Undefined method 'id' error using collection_select with form_for in Ruby on Rails
I'm having an issue with collection_select using form_for in rails. This issue is coming from a method that was working until I namespaced my routes to be only for admin. The admin routes are working as they should as far as I can tell, but it is…

mycupisoverflowing
- 63
- 1
- 8