Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read ruby on rails config values from within the application controller

If i have a configuration file like this

# config/environments/integration.rb config.action_controller.session = {   :domain => ".example.com" } 

How do I get the value from within my application controller, e.g:

# app/controller/application_controller class ApplicationController < Mcc::CoreSupport::FrontendController   def some_method     value = xxx   end end 
like image 553
keppla Avatar asked Dec 16 '09 17:12

keppla


People also ask

Where is Rails application config?

You probably know that you can configure Rails in config/application. rb and config/environments/development. rb etc. But you can also leverage that for configuring your own custom settings for your application.

What is Rails application config?

In general, the work of configuring Rails means configuring the components of Rails, as well as configuring Rails itself. The configuration file config/application. rb and environment-specific configuration files (such as config/environments/production.

What is application controller in Rails?

The Rails controller is the logical center of your application. It coordinates the interaction between the user, the views, and the model. The controller is also a home to a number of important ancillary services. It is responsible for routing external requests to internal actions.

What are Initializers in Rails?

An initializer is any file of ruby code stored under /config/initializers in your application. You can use initializers to hold configuration settings that should be made after all of the frameworks and plugins are loaded.


2 Answers

In Ruby on Rails 3 and above, you can access the config through Rails.application.config


In more recent versions, you can use Rails.configuration instead. For example: Rails.configuration.time_zone. See more in the official manual on configuration

like image 130
Melinda Weathers Avatar answered Sep 21 '22 21:09

Melinda Weathers


The class method ActionController::Base.session_options returns a hash of the configuration options for the session.

So in your case you want ActionController::Base.session_options[:domain]

like image 37
zetetic Avatar answered Sep 22 '22 21:09

zetetic