[英]Submit rails form with a field not in model
我需要提交一份表格,其中包含不屬於該模型的選擇。 保存操作后我需要此值用於其他操作,但是我收到錯誤:
undefined method `tecnico' for #<Interventi:0x9802cf8>
這是我表格的一部分:
<%= 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>
這是控制器
def nuovointervento
@titolo = "Nuovo Intervento"
@interventi = Interventi.new
@clienti = Clienti.all.order(:nome)
@categorie = Categorie.all
@tecnici = Utenti.where(operatore: '1').order(:nome)
結束
private
def parametri_intervento
params.require(:interventi).permit(:cliente_id, :data, :intervento, :note, :chiuso, :codice, :operator_id, :monteore, :categoria, :referente)
end
結束
是的,字段'tecnico'不屬於Interventi模型,但在后期操作中,保存后,我需要使用tecnico_id和創建的'intervento'id(它是連接表)保存其他記錄的值
我怎么解決?
保護你!
@EffeBi允許控制器中的此屬性像其他屬性一樣,例如:data
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.