Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6995579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:02:52+00:00 2026-05-27T20:02:52+00:00

I have a relatively small piece of initializer code that I want to run

  • 0

I have a relatively small piece of initializer code that I want to run whenever rails server runs, but not when I run rails generate, rails console or any other rails command (including rake tasks that require the environment task). This piece of code pre-fills some caches and is relatively expensive so I really don’t want it to run on anything but rails s

Solutions that are unsatisfactory:

Foreman et al. will mean it’ll run on a different process which is (a) over the top for that small piece of code, (b) requires interprocess communication instead of the simple in-memory approach afforded by the initializer.

On the server I’ve solved this by configuring passenger to pass a special environment variable into rails, telling it it’s running in server context. However I’d like it if possible to work out of the box on all developer’s machines without resorting to remembering to run rails server in a way that’ll also provide that environment variable (i.e IN_SERVER=true rails server).

This question has always been asked before with respect to running an initializer when running in rails server and not in rake. However I want it to run specifically only in server initialization – the fix for rake is great but isn’t comprehensive.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:02:53+00:00Added an answer on May 27, 2026 at 8:02 pm

    Can you do something like overriding Rails::Server#initializeso that it invokes your initialization code in your initializer?

    Or, more easily, just put your code in script/rails, as that will be run everytime you run rails server, you can easily fiddle with ARGV or ENV in there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have code that depends a relatively small MS Jet (created in Access) database.
I have a relatively small app that Im building using vb.net 2.0, and nant.
I have a piece of code that reads hell of a lot (hundreds of
I have a relatively small Java library that implements a few dozen beans (no
I have a Java app that fetches a relatively small .zip file using a
I have a c++ app that generates 6x relatively small image-like integer arrays per
I have a large number of (>100k) relatively small files (1kb - 300kb) that
I have a small application that process a large quantity of (relatively small) files.
I have a relatively simple site that I'm working up for an intranet environment.
We have are relatively simple Reporting Services report that our users commonly export to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.