Question

I have a user_inputs table where I am storing the device subscription statuses under a column sub_status and these subscription statuses I want as drop down options Under the same name. Now after selecting one option from the drop down I want to save the id of the status in equipment_assets table under a column_name subscription_status and display the status on the browser. I am trying collection_select for it but its not working.

<div class="pluginESV_formfield">
<%= f.label :subscription_status %><br />
<%= collection_select  :sub_status,UserInput.all,:id, :subscription_status %></div>

this gives error, wrong number of arguments, Please help me with this.

here-

  • :sub_status is the field which has the drop down options.
  • UserInput is the model from which these status are coming.
  • :id is the index of the sub_status from the user_inputs table
  • :subscription_status is the column in the equipment_assets table where selected IDs will be stored. I am not getting what's wrong with the code.

Please help me out with this.

Was it helpful?

Solution

For table equipment_assets with field subscription_status, you need to update collection_select as below:

<%= collection_select :equipment_asset, :subscription_status, UserInput.all, :id, :sub_status %>

As per the collection_select syntax, i.e.,

collection_select(object, method, collection, value_method, text_method, options = {}, html_options = {})

you missed the object argument which is why you got the error as wrong number of arguments. Its a mandatory argument as it helps to form select HTML element with proper id and name so that upon submission of form the selected value of select drop down will be passed in params hash correctly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top