Closed shardulmohite closed 6 years ago
This was not the problem with Aparment gem, rather it was issue with how I was trying to use dynamic path of paperclip. I should have used paperclip.interpolates to generate dynamic path instead of using it inside the path directly.
Solution is :
change the path to
:path => ":tenant/:class/:attachment/:id_partition/:style/:filename"
and then add below to your paperclip.rb file
Paperclip.interpolates :tenant do |attachment, style|
Apartment::Tenant.current
end
Steps to reproduce
I am trying to access Apartment::Tenant.current inside the models and specifically to use with paperclip path for s3.
Expected behavior
Apartment::Tenant.current should return current tenant consistenantly.
Actual behavior
It dosnt return current tenant consistently. I have to restart the server to get the correct tenant
System configuration
Macbook Pro - latest version
Database: (Tell us what database and its version you use.) Postgress
Apartment version: Latest
Apartment config (in
config/initializers/apartment.rb
or so): require 'apartment/elevators/subdomain' Apartment.configure do |config| config.excluded_models = %w{ Account } config.tenant_names = lambda { Account.pluck :subdomain } config.use_schemas = true end Rails.application.config.middleware.use Apartment::Elevators::Subdomain Apartment::Elevators::Subdomain.excluded_subdomains = ['www','admin']use_schemas
: (true
orfalse
)Rails (or ActiveRecord) version: Rails 5.1.5
Ruby version: ruby 2.4.0