Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I run an initializer from the rails console?

I've got an initialization file config/initializers/linkedin.rb that sets up the Linkedin gem so that my app can connect to the LinkedIn service and run queries. I'm now testing out some new features and I want to use the console for this. My problem - asside from being a newb and not understanding the console very well yet - is that I can't access the variables that are initialized in config/initializers/linkedin.rb.

Any ideas on how to use the application initializers from within the console so that I don't have to run this by hand every time?

Thanks!

like image 946
spinlock Avatar asked Mar 12 '12 16:03

spinlock


People also ask

How do I run a command in rails?

2.1 bin/rails serverGo 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 .

What is a Rails initializer?

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.

What are Railties?

Rails::Railtie is the core of the Rails framework and provides several hooks to extend Rails and/or modify the initialization process. Every major component of Rails (Action Mailer, Action Controller, Active Record, etc.) implements a railtie. Each of them is responsible for their own initialization.


1 Answers

Try this:

load "#{Rails.root}/config/initializers/your_file.rb"
like image 146
ecoologic Avatar answered Oct 30 '22 02:10

ecoologic