class Document < ActiveRecord::Base
belongs_to :user
has_many :attachments
accepts_nested_attributes_for :attachments
end
class DocumentsController < ApplicationController
def new
@document = get_user.documents.build
3.times { @document.attachments.build }
end
def create
@document = Document.new post_params
end
def post_params
params.require(:document).permit(:id, :subject, :body, attachments_attributes:[:attachment])
end
end
_form.html.slim嵌套屬性與軌道4個強參數
= f.fields_for :attachments do |builder|
= builder.file_field :attachment, multiple: true
這裏的問題是:
的附件上我post_params
是空的:
{"id"=>"", "to"=>"5621", "subject"=>"Hello", "body"=>"World", "attachments_attributes"=>{"0"=>{}}}
這是沒有問題的 – Dex