f.select rails 3.2 passing value

I have two problems (i think they are linked) :

1) i have to set a value from a f.select of a form.
i have in my view these two f.select:

  <div class="form-group">
    <label class="control-label col-sm-2" for="formagiuridica">Forma Giuridica:</label>
    <div class="col-sm-10">
    <%= f.select(:id, CompanyType.all.map { |m| [m.nome, m.id] }) %>

  <div class="form-group">
    <label class="control-label col-sm-2" for="settoreappartenenza">Settore Appartenenza:</label>
    <div class="col-sm-10">
        <%= f.select(:id, Sector.all.map { |m| [m.nome, m.id] }) %>

when i submit the form , i send these parameters:

enter image description here

The problem is , that i send only one of my f.select.
I think this is why i use id in the two f.select. Maybe rails is not able to undestand that these are two different f.select.
I tryed to change the name of the first parameter in the f.select (the id parameter):

from this:

<%= f.select(:id, CompanyType.all.map { |m| [m.nome, m.id] }) %>

to this:

<%= f.select(:company_type, CompanyType.all.map { |m| [m.nome, m.id] }) %>

but rails said to me:

undefined method `company_type' for #<Company:0x4002e10>

How can i solve this?

2)and also , i have to insert these two f.select in my strong parameters of my controller:

  def company_params
    params.require(:company).permit(:ragione_sociale, :indirizzo, :cap, :citta,:email,:telefono,:id)

what i have to write to permit the value of these two f.select?
thank you 🙂

Source: forms

Leave a Reply