微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ruby-on-rails – 使用Dragonfly进行Rails管理 – 编辑.没有档案

使用 Rails AdminDragonfly.但是当我创建了一个连接附件的新帖子时: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

解决方法

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

说明:认情况下,Dragonfly将附加文档存储在磁盘上(在文件存储中)到Dragonfly initializer中指定的目录.在数据库中,Dragonfly仅存储文档的名称和UID.在您的情况下,它是您正确添加到架构的ob_uid和ob_name列.

因此,除非您为文档配置了一些custom store,否则我假设您使用文件存储,并且不需要ob列.实际上,它会混淆rails_admin的dragonfly support code,实际上,编辑页面始终错误显示“没有选择文件”.

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

原文地址:https://www.jb51.cc/ruby/268124.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐