Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6011057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:12:17+00:00 2026-05-23T02:12:17+00:00

I’m creating a model in Ruby on Rails that will act like a file

  • 0

I’m creating a model in Ruby on Rails that will act like a file system. You’ll have assets (like files) that could either be folders or files themselves. How can I create a command for this?

Asset
  id (unique auto-incrementing number)
  name
  is_directory (bool)
  user_id (id of the owner)
  parent_asset_id (id of parent directory, or null if under the root)
  access_token (randomly generated token, used to send shareable links)
  contents

I’m thinking something like:

rails generate model Asset 
  name:string 
  is_directory:boolean 
  user_id:integer 
  parent_asset_id:integer 
  access_token:string contents:??

Some questions I have:

  1. What’s the difference betweeen blob vs longblob vs mediumblob vs longtext vs etc, and which would I want to use? (The assets are essentially text… not sure what the max size will be yet)

  2. Is the parent_asset_id a good naming convention, or is there something else that would make Rails give me some secret sauce, similar to why I picked the name user_id (to match the User model)?

  3. Is there a way to declare a default random string value for the access_token? (The access token will be used for a shareable link to the asset)

  4. Anything else I’m overlooking?

This is a detailed question, so I hope it serves as a case study for anyone looking to implement something like a file system in RoR.

Obviously if you really wanted to implement a file system you’d use an actual file system or Amazon S3… but if you want a light-weight file-like system in RoR, this seems like the best approach.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T02:12:18+00:00Added an answer on May 23, 2026 at 2:12 am

    First off, I strongly recommend you consider an existing gem like Paperclip, which will handle a lot of these details for you.

    Answers in order:

    1. You would use the binary field type to store general data, but if you use Paperclip there are some specific fields you would need to use instead, which are explained in Paperclip’s docs.

    2. If by parent_asset_id you really mean the asset can ‘belong’ to many other models, then look into setting up a polymorphic relationship, with an id and type field. If instead you mean storing the path to the stored file, then Paperclip handles this for you. See #3 for details…

    3. You can access a stored file on Paperclip by calling something as simple as asset.url in your view. If you wish to go manual and insert a random code, you can insert a callback into your Asset.rb model that does something like:

      before_create :generate_key
      
      def generate_key
        self.key = ActiveSupport::SecureRandom.hex
      end
      

    S3 is not a complex system to set up on Rails, and it is far more flexible and scaleable than storing the files elsewhere – however, if you want to, then use the ‘assets’ path.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I have thousands of HTML files to process using Groovy/Java and I need to
I have a reasonable size flat file database of text documents mostly saved in
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have some data like this: 1 2 3 4 5 9 2 6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.