【发布时间】:2016-11-07 18:42:19
【问题描述】:
我需要提交一个表单,其中包含一个不属于该模型的选择。保存操作后,我需要此值用于其他操作,但我收到错误:
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(它是一个连接表)
我该如何解决?
谢谢你!
【问题讨论】:
-
如果图片中有连接表并且出现这样的问题,那么你应该去accept_nested_attributes
标签: ruby-on-rails forms