Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Rails initializers gets called when I run rails console

I want to put my chargify conf inside the initializer, but I found the initializer won't execute in my rails c, is there a way to invoke my initializers so I can test in my console?

    Chargify.configure do |c|
      c.api_key   = "keykey"
      c.subdomain = "test-site"
    end
like image 449
user1883793 Avatar asked May 06 '16 04:05

user1883793


People also ask

How do Initializers work 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.

How do I start rails console?

Go to your browser and open http://localhost:3000, you will see a basic Rails app running. You can also use the alias "s" to start the server: bin/rails s . The server can be run on a different port using the -p option. The default development environment can be changed using -e .


2 Answers

The config/initializers will execute, but only once, on initial load. So if you're making changes to config/initializers while the console is running you won't see the results of those changes happening.

Your best option is to stop and restart rails c, or you can type the reload! command in the console.

Also, if you are using spring that will sometimes prevent changed initializers from reloading. in that case do spring stop before you restart the console.

like image 160
SteveTurczyn Avatar answered Sep 17 '22 20:09

SteveTurczyn


Apparently not anymore unless you disable spring:

export DISABLE_SPRING=1

like image 22
pguardiario Avatar answered Sep 18 '22 20:09

pguardiario