Get environment settings in rails controller

I have email settings in development.rb that I want to receive in my controller.

development.rb settings:

 config.notify_submited_transaction = ' anil@swiftsetup.com , anildbest83@gmail.com ' config.notify_approved_transaction = ' anil@swiftsetup.com ' 

In my controller / action, I am trying to do this:

  @to = Rails.env.notify_submited_transaction @subject = 'AM - Vendor Submitted Transaction' AmMailer.vendor_submited_transaction(@to, @subject, current_user).deliver 

This results in an error:

  undefined method `notify_submited_transaction' 

I am not sure how to get the configuration value that I set.

Thanks for any help.

+6
source share
2 answers

Try to access:

 Rails.application.config.notify_submited_transaction Rails.application.config.notify_approved_transaction 

Similar to: For Rails, how to access or print configuration variables (as an experiment or test / debugging)

+4
source

Just workaround: Rails.env is a special string object that allows you to get the current environment (it doesn't look like Rack env):

 puts Rails.env # => "production" puts Rails.env.test? # => false 

It is not intended to return configuration settings.

This may come in handy if you want to put your user preferences in /config/initializers/* , and for clarity, this is the best way in some cases (it is recommended not to clutter the rails environment files with your custom settings). For instance:

 # config/initializers/mailer_settings.rb if Rails.env.production? ActionMailer::Base.smtp_settings = { :address => "smtp.gmail.com", ... } else #different settings end 
+17
source

Source: https://habr.com/ru/post/912906/


All Articles