Rails Admin With Dragonfly - Edit. No files

Using Rails Admin with Dragonfly , However, when I created a new entry with an attached file :ob to dragonfly and want to edit it. This is sais "File not selected". How does he not understand that there is already a file?

In my rails_admin, I did this.

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

Here is my model:

 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 

Here is my diagram:

 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 

Is there anything else I need to do so that it takes the file?

https://github.com/sferik/rails_admin

https://github.com/markevans/dragonfly

+7
ruby-on-rails dragonfly-gem rails-admin
source share
1 answer

I managed to reproduce your problem using the configuration you provided, and the fix that worked for me was incredibly simple: just remove the ob column from the documents table .

Explanation: By default, Dragonfly stores attached documents on disk (in the file vault) in the directory specified in Dragonfly Initializer . Dragonfly only stores the name and UID of documents in the database. In your case, these are the ob_uid and ob_name columns that you correctly added to your schema.

So, if you have not set up any custom document store , I assume that you are using the default file vault and you don’t need the ob column. In fact, he confuses the rails_admin dragonfly support code in such a way that in fact the edit page does not correctly display β€œNo file selected” all the time.

Adding an image after fixing (for simplicity, I removed the association document_categories both the model and the editing actions in rails_admin):

Adding image after correction

+2
source share

All Articles