Rails 4.2.1,Ruby 2.2.1和PostgreSQL 9.3
我有region
和pattern
型号
class Region < ActiveRecord::Base
has_many :patterns, dependent: :destroy
accepts_nested_attributes_for :patterns, reject_if: :all_blank, allow_destroy: true
end
class Pattern < ActiveRecord::Base
belongs_to :region
has_attached_file :picture
validates_attachment_content_type :picture, content_type: "image/png"
end
以cocoon
宝石
= simple_form_for(@region) do |f|
= f.simple_fields_for :patterns do |pattern|
= render 'pattern_fields', f: pattern
.links
= link_to_add_association 'add pattern', f, :patterns
_pattern_fields.html.slim
查看
.nested-fields
.form-inline
= f.input :picture, as: :file
= link_to_remove_association f, class: 'btn btn-default btn-xs' do
.glyphicon.glyphicon-remove
我可以轻松创建具有多个模式的区域,但是当我单击编辑时,文件字段为空。
使用回形针正确处理文件字段和轨道表单有什么好方法吗?