附件没有以编辑形式填写

时间:2015-07-08 11:38:31

标签: ruby-on-rails paperclip simple-form cocoon-gem

Rails 4.2.1,Ruby 2.2.1和PostgreSQL 9.3

我有regionpattern型号

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

我可以轻松创建具有多个模式的区域,但是当我单击编辑时,文件字段为空。

enter image description here

使用回形针正确处理文件字段和轨道表单有什么好方法吗?

0 个答案:

没有答案