Ask A Question

Notifications

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
instance.send(attachment).path
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.
Reply
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".
Reply

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'
/Users/nicknoble/products/Lnky/db/migrate/20180531013954_convert_to_active_storage.rb:14:in
up'

Reply
Same here! :/
Reply

Same here :(

Reply

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 (?, ?, ?, '{}', ?, ?, ?)
    SQL

    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}, ?)
    SQL
Reply
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.  


Reply
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.
Reply
When can we actually remove paperclip?
Reply

No (offical) way to use validations (https://github.com/thoughtbot/paperclip#validations) for Active Storage yet. Mayor bummer …

Reply
Reply

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.

Reply

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?

Reply

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.

Reply
Join the discussion
Create an account Log in

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

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

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