不与嵌套表单附加的属性

时间:2017-11-10 21:57:37

标签: ruby-on-rails carrierwave nested-forms

我正在尝试从rails中的嵌套表单创建一个对象,但我似乎无法让params看起来像他们应该的那样。

我有SubmissionAttachment型号

ATTACHMENT

class Attachment < ApplicationRecord
  mount_uploader :file, FileUploader

  belongs_to :submission
end

的提交

class Submission < ApplicationRecord
  has_many :attachments, inverse_of: :submission
  accepts_nested_attributes_for :attachments, reject_if: :all_blank, allow_destroy: true
end

CONTROLLER

def new
  @submission = ComplianceSubmission.new(user_id: current_user.id)
  @submission.attachments.build
end
形成
<%= form.fields_for :attachments, submission.attachments do |attachment_fields| %>
  <%= attachment_fields.file_field :file %>
<% end %>

PARAMS

<ActionController::Parameters {"utf8"=>"✓", "authenticity_token"=>"tY5gRq1YJatO/wHHltCtBr34ZpgIAofJBCNcStiWUrAh0NavrAvHNjhesqMl0aRct9wlBQacpnaietb654JtsA==", "compliance_submission"=><ActionController::Parameters {"compliance_selection"=>"Professional Designation", "attachments"=>{"file", "compliance_conversation"=>"", "compliance_conversation_user"=>"Grady Ledner", "compliance_conversation_time"=>"Nov 10, 4:44 PM", "compliance_note"=>""} permitted: false>, "commit"=>"Submit Form", "controller"=>"compliance_submissions", "action"=>"create"} permitted: false>

嵌套属性参数像"attachments"一样转到控制器,它们看起来像"attachments_attributes"。另外,系统不知道创建模型。

有人知道我做错了吗?

0 个答案:

没有答案