Reputation: 81
I am looking to use a application variable as set in application_controller
application_controller.rb
def current_company
@current_company ||= Company.find(cookies[:default_company]) if cookies[:default_company]
end
how do I now use current_company.id in the uploader (company_logo_uploader.rb)
def store_dir
"uploads/#{current_company.id}/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
I get a undefined local variable or method `current_company' for :CompanyLogoUploader
help would be much appreciated.
Upvotes: 1
Views: 1606
Reputation: 5962
You have to call the instance method defined on your class with model.
definition prepended to it
Try this
"uploads/#{model.current_company.id}/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
Make sure @current_company
is set else it would return nil
Upvotes: 3