1

What are the changes to be made in the controllers and the collection for accepting multiple values from a collection select.

The association between the models is:-

product has many categories through product_categories
categories has many products through product_categories

product_categories is the join table.

Below is my collection select, where i am using chosen to select multiple values.

<%= ps.collection_select :product_id, Product.all, :id,   :product_name, {prompt: "Select Product"}, {class: "form-control chosen-select",:multiple => true}

Controller params

params[:spare].permit(:id, :name, :desc,:code,:manufacturer_id, :product_ids,{:attachments_attributes => [:id, :attachment, :remote_attachment_url, :_destroy]})

Also tried with nested attributes

params[:spare].permit(:id, :name, :desc,:code,:manufacturer_id,:product_ids,{manufacturer_service_centers_attributes: [:id, :service_center_id, :manufacturer_id, :_destroy]},{:attachments_attributes => [:id, :attachment, :remote_attachment_url, :_destroy]})

What changes should i do here for it to take product_ids? .

Atchyut Nagabhairava
  • 1,295
  • 3
  • 16
  • 23
Pallavi Hegde
  • 219
  • 2
  • 15
  • just refer http://stackoverflow.com/questions/23253449/ruby-on-rails-4-select-multiple – Pardeep Saini May 25 '16 at 09:54
  • i did check it.. but i dont find the controller part there and the data is populated statically, i wanted to know how to pass the hash or array dynamically in collection select. – Pallavi Hegde May 25 '16 at 10:00
  • @PallaviHegde can you post your `params` hash value from console & also add the entire form of your view template. – dp7 May 25 '16 at 10:23

1 Answers1

0

I was able to apply chosen multi select, These are the steps i followed.

with chosen select:

<%= f.select :product_ids, Product.all.collect { |u| [u.product_name_code, u.id] }, {}, {:multiple => true, :class => "chosen-select"} %> 

Controller

params[:spare].permit(:id,:product_ids => []) 

Hope it helps :)

Thanks :)

Pallavi Hegde
  • 219
  • 2
  • 15