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

前端之家收集整理的这篇文章主要介绍了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.f2er.com/ruby/268124.html

猜你在找的Ruby相关文章