Joined October 2014



I'm implementing select2 tagging with a has_many through relationship. My implementation has 2 different scenarios.

  1. The select menu allows multiple (tagging) but does not allow on the fly input into the select menu.
  2. Same as above but uses ajax to allow the user to enter new select values on the fly.

Scenario 1 works well for tagging. Scenario 2 seems to work but does not save the values. My problem seems to come down to my my input elements for the scenarios.

Scenario 1 uses:
<%= f.association :repairers, labelmethod: :repname, valuemethod: :id, includeblank: true, label: 'Repairer'%>
and when the form is submitted gives params similar to:
"repairer_ids"=>["", "1132", "1131"]

Scenario 2 uses:
<%= f.hiddenfield :repairtypeid, :class => "required on-the-fly-select select"%>
and uses a lot of js code to implement on the fly input for the select menu. When the form is submitted the data will look like: "repair

So with scenario 2 the ids are not submitted as an array. I have tried changing the select to: <%= hiddenfieldtag("repairitem[repairtypeids][]", "", :id => "repairitemrepairtypeids", :class => "required on-the-fly-select select") %>
but then the relevant param is submitted as one array: "repair

Are you able to comment on this? Have you ran into this problem?

1 Karma
0 Total ProTip Views