繁体   English   中英

Rails管理员使用Dragonfly - 编辑。 没有档案

[英]Rails Admin With Dragonfly - Edit. No file present

使用Rails管理员Dragonfly 但是,当我创建一个连接附件的新帖子时:ob to dragonfly并想要编辑它。 这是“没有选择文件”。 因为它没有拿起已存在的文件?

在我的rails_admin中,我做到了这一点。

edit do
  field :name
  field :information
  field :ob, :dragonfly
  field :document_categories
end

这是我的模特:

class Document < ActiveRecord::Base
  has_and_belongs_to_many :document_categories


  after_commit :generate_versions, on: :create
  dragonfly_accessor :ob


  validates :name, :ob, presence: true

  def generate_versions
    DocumentWorker.perform_async(self.id)
  end

  def convertable_image?
    unless self.try(:ob).nil?
      self.try(:ob).mime_type.include?("image") || self.try(:ob).mime_type.include?("pdf")
    else
      return false
    end
  end

  def respond_with_type
    case self.try(:ob).mime_type.split("/")[1]
      when "vnd.ms-powerpoint" , "vnd.openxmlformats-officedocument.presentationml.presentation", "application/vnd.openxmlformats-officedocument.presentationml.template"
        "powerpoint"
      when "application/vnd.ms-excel" , "vnd.openxmlformats-officedocument.spreadsheetml.sheet"
        "excel"       
      when "application/msword" , "vnd.openxmlformats-officedocument.wordprocessingml.document"
        "word"                
      else
        self.try(:ob).mime_type.split("/")[1]
      end
  end  
  default_scope{order("name ASC")}
end

这是我的架构:

create_table "documents", force: :cascade do |t|
    t.string   "name"
    t.string   "ob"
    t.datetime "created_at",  null: false
    t.datetime "updated_at",  null: false
    t.string   "ob_uid"
    t.string   "ob_name"
    t.text     "information"
  end

还有什么我需要做的才能拿起文件吗?

https://github.com/sferik/rails_admin

https://github.com/markevans/dragonfly

我设法使用您提供的配置重现您的问题,并且对我有用的修复结果非常简单:只需documents表中删除ob

说明:默认情况下,Dragonfly将附加文档存储在磁盘上(在文件存储中)到Dragonfly初始化程序中指定的目录。 在数据库中,Dragonfly 存储文档的名称和UID 在您的情况下,它是您正确添加到架构的ob_uidob_name列。

因此,除非您为文档配置了一些自定义存储 ,否则我假设您使用默认文件存储,并且不需要ob列。 事实上,它会混淆rails_admin蜻蜓支持代码 ,实际上,编辑页面始终错误地显示“没有选择文件”。

修复后添加图像(为简单起见,我从rails_admin中的模型和编辑操作中删除了document_categories关联):

修复后添加图像

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM