Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run my ruby code after Rails server start?

I tried:

after_initialize do   #code end 

But: (documentation)

Some parts of your application, notably observers and routing, are not yet set up at the point where the after_initialize block is called.

I need routing and logger in my code

Any ideas?

like image 515
user1103291 Avatar asked Dec 17 '11 09:12

user1103291


People also ask

How do I run a Ruby on Rails server?

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 .

What happens when Rails server starts?

One of the things rails server does is that it loads all the dependencies/gems required by your Rails app, or at least sets them up to be auto-loaded later when they are needed. This is sometimes called "booting" or loading the "Rails environment".

How do I run an existing Ruby on Rails project?

How to run an existing Ruby-on-Rails project locally after cloning a repository. The first thing to do is to find the Ruby version used in the Rails project. Then, install the ruby version, bundler gem, dependencies (packages). Finally, set up the database and run the Rails project.


1 Answers

See section 3.1 from http://guides.rubyonrails.org/configuring.html

I believe you would put this code in config/application.rb

config.after_initialize do     # .... end  # config.after_initialize takes a block which will be run after Rails has finished initializing the application.  # That includes the initialization of the framework itself 

Also http://guides.rubyonrails.org/initialization.html

like image 194
house9 Avatar answered Sep 21 '22 14:09

house9