0

我有一个 has_man 通过关联。当我转到商店表单时,我需要以相同的表单保存所有者数据。但我不断得到Unpermitted parameters: :offices。我也尝试过使用 inverse_of 。我尝试更改模型结构,例如尝试接受所有模型的属性。

办公模式:

class Office < ApplicationRecord

  has_many :owner_offices, :dependent => :destroy
  has_many :owners, through: :owner_offices

  accepts_nested_attributes_for :owner_offices
  #accepts_nested_attributes_for :offices

end

车主型号:

class Owner < ApplicationRecord
  has_many :owner_offices
  has_many :offices, through: :owner_offices

  accepts_nested_attributes_for :owner_offices
end

Owner_Office 型号:

class OwnerOffice < ApplicationRecord
  belongs_to :office
  belongs_to :owner

  accepts_nested_attributes_for :owner
end

办公室控制器:

def new
  @office = Office.new
  @office.owners.build
end

def office_params
  params.require(:office).permit(:office_name, :office_slug, :office_email, :phone, :office_type, :status, :mf_member, :comment,
  :owners_attributes => [:office_id, :owner_id, :first_name, :last_name, :owner_email])
end

办公形式:

<%= form_with(model: office, local: true, html: {class: "form-office"}) do |form| %>
  <div class="row">
    <div class="col-md-6 col-sm-6 col-xs-12">
      <div class="form-group">
        <span><%= form.label :office_email %></span>
        <%= form.text_field :office_email, class: 'form-control' %>
      </div>
    </div>
  </div>
  <hr>
  <h3>Owner Information</h3>
  <hr>
<%= form.fields_for :owners do |owner_form| %>
  <div class="row">
    <div class="col-md-6 col-sm-6 col-xs-12">
      <div class="form-group">
          <span><%= owner_form.label :first_name %></span>
          <%= owner_form.text_field :first_name, class: 'form-control' %>
      </div>
    </div>
    <div class="col-md-6 col-sm-6 col-xs-12">
      <div class="form-group">
          <span><%= owner_form.label :last_name %></span>
          <%= owner_form.text_field :last_name, class: 'form-control' %>
      </div>
    </div>
  </div>

  <div class="row">
    <div class="col-md-6 col-sm-6 col-xs-12">
      <div class="form-group">
          <span><%= owner_form.label :owner_email %></span>
          <%= owner_form.text_field :username, class: 'form-control' %>
      </div>
    </div>
  </div>
<% end %>
<% end %>

我只是将大部分部分放置在我调用fields_forfor owner的位置。所以我被卡住了,不确定我目前缺少什么,我也一直在检查其他资源,实施不同的逻辑。

另外,我不想使用茧,因为对我来说学习如何从头开始实施很重要。

提前致谢。

4

0 回答 0