Rails + Dragonfly gem: Saving image in a directory structure based on ActiveRecord object attributes
- by Allen Bargi
I'm using dragonfly gem to manage images and attachments in my rails app and I need to store images in a specific directory structure based on my
user model.
let' say I have user model which has a name and each user has many
albums, which have a name also, then I want the images to be stored
in "#{RAILS_ROOT}/public/system/#{user.name}/#{user.album.name}/#{suffix}"
I've managed to changed the root_path in dragon fly and I even
overrided relative_storage_path like this:
class MyDataStore < Dragonfly::DataStorage::FileDataStore
private
def relative_storage_path(suffix)
"#{suffix}"
end
end
but still, I don't know how I can pass the ActiveRecord object
attributes like user.name and user.album.name to relative_storage_path
to create my ideal path.
do you have any idea how I can do such a thing?