Gustavo Borges
Gustavo Borges

Reputation: 107

How do I lazy-load a config from an initializer?

I'm using Rails 6 with the 'money-rails' gem (for multiple currencies) and 'apartment' gem (for multi-tenancy). In the 'money-rails' documentation it is said that I could lazy-load the configuration of the default currency of the app, by using doing something like this:

# config/initializers/money.rb
MoneyRails.configure do |config|

  # set the default currency based on client configuration
  config.default_currency = -> { Tenant.current.default_currency }
end

I have a Tenant model with a default_currency column. But, if I try to use something like this example, I get an 'method missing error', probably because the class Tenant is not loaded yet and it's not possible to find a current tenant. What is the best way round this problem?

`method_missing': undefined method `has_one_attached' for Tenant:Class (NoMethodError)

This is the money-rails documentation.

Upvotes: 1

Views: 123

Answers (0)

Related Questions