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 8686785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:57:09+00:00 2026-06-12T22:57:09+00:00

I am developing a gem for my Rails application, which be loaded into it

  • 0

I am developing a gem for my Rails application, which be loaded into it through Railtie. I’m basically inserting models into into, plus libraries and a few initializers, in the old Rails app style. My main concern is not knowing exactly in the whole Rails application loading logic where I should best insert them. My requirement for it is: the gem initializers have to be loaded before the app initializers, same thing with the libs, and the initializers access lib information. In the Rails app workflow, it somehow works. My short-term workaround was the following:

module Gemname
  def self.initialize_railtie
    ActiveSupport.on_load :active_record do
      require 'gemname/lib'
      require 'gemname/initializers'
    end
  end
  class Railtie < Rails::Railtie
  initializer 'gemname.insert_into_app' do
    Gemfile.initialize_railtie
  end
end 

So this way, I’m sure that the libs are loaded before the initializers. Just I’m pretty sure there is a better way to do it, namely, access some railtie hook which allows me to load my libs with the app libs and the initializers with the app initializers. Just I can’t seem to be able to find them.

  • 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-06-12T22:57:11+00:00Added an answer on June 12, 2026 at 10:57 pm

    I think what you want is config.after_initialize. According to here:

    Last configurable block to run. Called after frameworks initialize.

    and here:

    after_initialize: Run directly after the initialization of the application, but before the application initializers are run.

    So you would have:

    module Gemname
      class MyCoolRailtie < ::Rails::Railtie
        config.after_initialize do
          require 'gemname/lib'
          require 'gemname/initializers'
        end
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing Rails application and I have to use authentication. I installed devise gem
How can I convert the Forum application I've been developing into a Rails Engine,
I am developing a Rails 3 application from which I want to be able
I am developing this Rails 3.2 application using the Apartment gem as middleware. The
I am developing a rails application which should send push notifications to iOS devices.
I am developing a small Ruby-on-rails application. I am using 'roo' gem to open
I am developing an application in rails which requires checking whether a sitemap of
I have a Mac which I use for developing Ruby on Rails applications. I
I'm developing an application using rails 2.3.5, gitorious and deploy with vlad, the OS
I'm developing a Ruby on Rails application need some advanced search engine functionality: specifically,

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.