logos
对于我的模型
cover
通过表单。
遵循本教程:
Handling file upload with ROR 5
徽标
徽标
掩蔽
我无法解决的问题是当我试图挽救
掩蔽
错误似乎在
save attachment
方法
= simple_form_for [current_user, @book, @cover], html: { multipart: true } do |f|
= f.label :logos, 'Votre logo', class: "field-label center"
= f.file_field :logos, multiple: true, class: 'text input-border hidden-always'
= f.submit "enregistrer", class: "button w-button", data_wait: "Patientez svp"
class Logo < ApplicationRecord
has_attached_file :file
belongs_to :cover
do_not_validate_attachment_file_type :file
end
封面.rb
class Cover < ApplicationRecord
has_many :logos, dependent: :destroy
attr_accessor :logos
def save_attachments(params)
params[:logos].each do |doc|
self.logos.create(:file => doc)
end
end
end
covers\u controller.rb
class CoversController < ApplicationController
def create
if @cover.save
@cover.save_attachments(cover_params) if params[:cover][:logos]
...
end
end
private
def cover_params
params.require(:cover).permit(:name, logos: [])
end
end
end
如果我更改
attr_accessor :logos
到
attr_accessor :logos_data
,我明白了