加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-17 04:14:23 所属栏目:百科 来源:网络整理
导读:使用 Rails Admin和 Dragonfly.但是当我创建了一个连接附件的新帖子时:ob to dragonfly并想要编辑它.这是“没有选择文件”.因为它没有拿起已存在的文件? 在我的rails_admin中,我做到了这一点. edit do field :name field :information field :ob,:dragonfl
使用 Rails Admin和 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

解决方法

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

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

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读