Ask A Question


You’re not receiving notifications from this thread.

How to Migrate from Paperclip to Rails ActiveStorage Discussion

This should return the path to file in this format: /users/avatar/xxx/xx/original/filename
Also, in my case i had to use something like:
file_path = k.send(value).path.split('/system', 2).second
because it exists locally and path had system as a prefix.
For Digital Ocean Spaces, could you check the ETag of an object for the checksum rather than downloading the entire thing? Their docs say the ETag is "an MD5 hash of the object".

When I run the migration (with the provided code) I get:

ArgumentError: wrong number of arguments (given 1, expected 2..3)
/Users/nicknoble/products/Lnky/db/migrate/20180531013954_convert_to_active_storage.rb:14:in prepare'

Same here! :/

Same here :(


I fixed this by changing to:

active_storage_blob_statement = ActiveRecord::Base.connection.raw_connection.prepare(<<-SQL)
      INSERT INTO active_storage_blobs (
        `key`, filename, content_type, metadata, byte_size, checksum, created_at
      ) VALUES (?, ?, ?, '{}', ?, ?, ?)

    active_storage_attachment_statement = ActiveRecord::Base.connection.raw_connection.prepare(<<-SQL)
      INSERT INTO active_storage_attachments (
        name, record_type, record_id, blob_id, created_at
      ) VALUES (?, ?, ?, #{get_blob_id}, ?)
When running migration:

ArgumentError: You tried to define an enum named "industry" on the model "Company", but this will generate a instance method "horeca?", which is already defined by another enum.  

I think this is because of the first line, when we require all the models. I just commented that line out and worked without that kind of error.
When can we actually remove paperclip?

No (offical) way to use validations ( for Active Storage yet. Mayor bummer …


Instead of building the URL in the def key method, can't I use the same thing I used in checksum?
url = attachment.url
I'm attempting to modify this migration to transition from Shrine to Active Storage.


get_blob_id = LASTVAL() was returning the id from the attachments table, NOT the blob_id. I had to change it to get_blob_id = "(SELECT max(id) from active_storage_blobs)". Any thoughts on this?


Quick question before starting this process. How can you approach this for multi tenant app with apartment gem? Has you use different DBs for the tables. Thank in advance.

Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 81,149+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

    © 2024 GoRails, LLC. All rights reserved.