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…
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,…
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…
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