提交带有不在模型中的字段的Rails表单

Eff*_*eBi 5 forms ruby-on-rails

我需要提交一个表格,并且选择一个不属于该模型的表格。保存动作后,我需要将此值用于其他操作,但出现错误:

undefined method `tecnico' for #<Interventi:0x9802cf8>
Run Code Online (Sandbox Code Playgroud)

这是我表格的一部分:

<%= 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>
Run Code Online (Sandbox Code Playgroud)

这是控制器

 def nuovointervento
@titolo = "Nuovo Intervento"
@interventi = Interventi.new
@clienti = Clienti.all.order(:nome)
@categorie = Categorie.all
@tecnici = Utenti.where(operatore: '1').order(:nome)
Run Code Online (Sandbox Code Playgroud)

结束


private
def parametri_intervento
  params.require(:interventi).permit(:cliente_id, :data, :intervento, :note, :chiuso, :codice, :operator_id, :monteore, :categoria, :referente)
end
Run Code Online (Sandbox Code Playgroud)

结束


是的,字段“ tecnico”不属于Interventi模型,但是在后期操作中,保存后,我需要使用tecnico_id和创建的“ intervento” id(此为连接表)保存该值用于其他记录

我该如何解决?

保护你!

Eff*_*eBi 5

抱歉,正如 MageeWorld 所说,这篇文章是重复的。

表单字段中的 answare 不属于 rails db 模型的一部分 解决了我的问题!

谢谢大家