Skip to main content

Rails Engine - How To Keep Your Engine Migrations Abstracted From Your Host Rails App



Have you ever worked on building a Rails Engine and wanted to keep the models, the migrations and everything inside the engine rather than using a generator to copy paste them into your host Rails App? That's a problem everybody faces one time or the other when building Rails Engines to abstract out your huge Rails App. I have found one such solutions that can be helpful for you to keep them separate. Here is a solution for it.

Problem Statement:

Instead of using

    rails g my_engine:install

to copy paste the migrations from engine to your rails app, you want to just keep the migrations inside the Rails Engine and do not bother about it.

Solution: 

Add the following lines to your engine, so that your engine's migration files are added to the rails app as well.


Now you can do the following from your rails app to run your migrations as you always do:

    rake db:migrate

Hope it helps you! If it does help you, give me a shoutout below!

Talk to me on Twitter, Facebook, LinkedIn or Website.

Comments

Featured

You are in a cold conference room, Do you want to use your mac as a heater?

Imagine that you are in cold conference room and you kind of feeling the cold on your head. What do you do when you are in a serious meeting and just can't get out?

If you have a MacBook, you might have a solution.

Use your terminal to run either of these commands to keep your CPU at above 80% or if you want you can run them both.

$ openssl speed

and/or 

$ yes > /dev/null

The first command just outputs the ssl cryptography stats and it keeps your cpu busy. The second command just prints the character "y" into IO.

So try it out and let me know how it works! :D


Talk to me on Twitter, Facebook, LinkedIn or Website
You will receive wonderful short stories written by him and inspirational articles once every month.