# Railtie initializer and generators

**URL:** <https://www.ruby-forum.com/t/railtie-initializer-and-generators/208621>\
**Category:** Rails\
**Created:** [June 22, 2011, 8:29pm UTC](https://www.ruby-forum.com/t/railtie-initializer-and-generators/208621 "2011-06-22T20:29:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [June 22, 2011, 8:29pm UTC](https://www.ruby-forum.com/t/railtie-initializer-and-generators/208621/1 "2011-06-22T20:29:59Z")

</div>

I am creating a gem for a Rails project and I got some troubles to  
understand how generators and initializers work. I would like to  
initialize my module loading some stuff from the database from models  
related to tables my gem should create with a migration file.  
Problem is : if I create a Railtie and put it my gem lib directory,  
when I try to run my generator (to create the migration template file  
for example), it’s already trying to run the Railtie even though  
tables required don’t exist yet.

How to restrict the “scope” of the Railtie ? I would like it only to  
run when booting Rails from a server (webrick, thin, …) or from the  
console, but not for any rake tasks (including generators). I think  
that rake tasks (like generators) load the entire Rails environment  
and my problem should come from that.  
Is there a simpler way to do that ?

any help or advice appreciated.

Florent
