-
Notifications
You must be signed in to change notification settings - Fork 1.7k
CarrierWave and multiple databases
Andreas Wagner edited this page Feb 14, 2017
·
5 revisions
If you are using multiple databases in your Rails application, it's important to save files in different directories, for example named like subdomains. This is my example solution:
ApplicationController.rb
def override_db
...
redefine_uploaders_store_dir
end
def redefine_uploaders_store_dir
CarrierWave::Uploader::Base.descendants.each do |d|
d.class_eval <<-RUBY, __FILE__, __LINE__+1
def store_dir
"uploads/#{@current_subdomain}/\#{model.class.to_s.underscore}/\#{mounted_as}/\#{model.id}"
end
RUBY
end
end