Implements a database-based file system implementation

Since the "file system" and the "rails" are such common themes, both together and separate, I cannot find any open source Ruby on Rails application that implements the file system in the database. I would like to use such an application as a starting point or template.

I have already been able to implement the User and Directory models (using Ancestry for the latter), and I find my path to the File model (my application needs only one kind of file).

 class User < ActiveRecord::Base attr_accessible :email, :name, :password, :password_confirmation has_secure_password has_many :directories, dependent: :destroy # ... end # class User class Directory < ActiveRecord::Base attr_accessible :name, :parent_id has_ancestry belongs_to :user has_many :files, dependent: :destroy # ... end # class Directory # not actually implemented, yet class File < ActiveRecord::Base attr_accessible :name belongs_to :directory # ... end # class File 

In views, I use jsTree to represent the tree and the form for adding / removing, editing, ... This will need to be changed to use AJAX , since redirecting back to the same page does not save the expanded / collapsed state of the tree.

However, I have this feeling when I do what has already been done many times. Can you provide links to such applications or give recommendations on the implementation of both part of the model and part of the presentation?

+6
source share
2 answers

Model Implementation Guidelines

In order for the model to be organized as a tree structure, tecnique is known as the Nested dialing model , so the common name (useful for searching on Google, etc ..) can be "Logo attachment" ;-)

Your choice of Ancestry is welcome, but you can enjoy viewing projects (mix-in, plug-in, ...), for example:

For the download part of the 'n store' file, I would suggest, in addition to the already mentioned Piperclip, to see carrierwave itself provides storage based on “foggy” pearls (supports file storage using AWS, Google, Local and Rackspace), but you can choose the base storage data (e.g. sqlite) using carrierwave-activerecord

Recommendations for using the view

About the “views” that may interest you this answer is about the jQuery file tree, a custom AJAX file browser plugin for jQuery and dnamique blog , which has a rail connector for this plugin and sources and demo .

alternatively, look at the implementation (sources) of the applications mentioned in the next section.

Links to such applications

Here is some "file manager":

  • Boxroom
  • Saphyra (available as a mounted engine)
  • Rail based CMS can be interesting code
+5
source

I think you're on the right track. The Directory and File models look great.

Your disgust is partly true. This is a common requirement to support file loading and storage, but it is not so important for modeling and displaying the entire hierarchical directory structure.

You might want to review the actual storage of files in the database. This is usually a bad idea. Because files are so variable in size, they can inflate your table and degrade performance. I recommend storing your files on Amazon S3. This is a much more reliable and fast storage, and you can serve S3-URL directly for clients to reduce bandwidth and load your own servers. You can use paperclip gem to process file downloads and store files either on disk or on S3.

+3
source

Source: https://habr.com/ru/post/945198/


All Articles