I want to grab config settings for a module, and I was told to use an initializer for this.
Can someone show me how to do this and how I will reference the config settings from the initializer?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The initializer facility of Ruby on Rails allows you to run arbitrary bits of code after the main application has been loaded but before any pages have been rendered. These are one-shot things, too, and the application has to be restarted if any are changed.
If you want to configure or reconfigure a module, you just sort of do it. There’s nothing fancy required. Typically they look something like this:
It will depend on what you are trying to configure of course. You can declare extensions to classes, load in additional modules, anything that might be required for your application to work properly.
Generally it’s bad form to force-load a plugin or gem that was not loaded automatically, but as with anything, sometimes you need to break the rules to get your app working.