i need to submit a form, with a select thath not belong to the model. I need this value for other operation after save action, but i receive the error:
undefined method `tecnico' for #<Interventi:0x9802cf8>
This is part of my form:
<%= form_for :interventi, url: welcome_nuovointerventosalva_path do |f| %>
<div class="row">
<div class="col-md-2">
<%= f.label :data, 'Data creazione' %>
<div class="form-group input-group">
<span class="input-group-addon"> <i class="fa fa-calendar"></i> </span>
<%= f.text_field :data, :class => "date-picker form-control input-mini", readonly: true, :value => Time.now.strftime("%Y/%m/%d") %>
<!--<span class="help-block">formato YYY-MM-DD</span> -->
</div>
</div>
....................................
....................................
<div class="col-md-3">
<%= f.label 'Tecnico' %>
<div class="form-group input-group">
<%= f.select :tecnico, options_for_select(@tecnici.collect{ |tec| [tec.nome, tec.id] }), {}, class: 'form-control search-select' %>
</div>
</div>
and this is the controller
def nuovointervento
@titolo = "Nuovo Intervento"
@interventi = Interventi.new
@clienti = Clienti.all.order(:nome)
@categorie = Categorie.all
@tecnici = Utenti.where(operatore: '1').order(:nome)
end
private
def parametri_intervento
params.require(:interventi).permit(:cliente_id, :data, :intervento, :note, :chiuso, :codice, :operator_id, :monteore, :categoria, :referente)
end
end
Yes, the field 'tecnico' doesn't belong to Interventi model, but in post action, after save, i need this value for other record save with tecnico_id and the created 'intervento' id (it's a join table)
How can i solve?
Tank you!
Sorry, as MageeWorld sayed, this post was a duplicate.
the answer in Form field not part of rails db model solved my problem!
Thanks to all
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With