7

So I'm working on a new project that seems like a great choice for using the new Engine functionality. It's as engines say, its own little app, w/ its own views and controllers and models. Here's where I'm coming up short.

I create my test application in which I will mount the new engine.

rails new engine_app && cd engine_app

I then create the new engine

rails plugin new my_engine --mountable

I then add the 'gem' to the engine_app's gemfile

gem 'my_engine', :path => './my_engine'

I then mount the engine in engine_app's routes as so

mount MyEngine::Engine, :at => '/my_engine'

I then cd into my_engine's dummy app and run

rails generate model MyModel title:string body:text

Here's where I run into my confusion. From what I understand this is supposed to generate a namespace table (I think it would be my_engine_my_model). The table in the migration file is just my_model.

Secondly how do I run this migration and is the migration file correct in only calling the table :my_model? I have tried running the following but nothing seems to happen, and I've checked the database and the table isn't there.

So to recap, I need to know how to create migrations in the engine, and be able to run them on the parent apps database correctly.

Thanks for any help and guidance.

kwbock
  • 647
  • 5
  • 13

2 Answers2

5

So all of the tutorials I read didn't specify that you needed to run script/rails generate from within the root level of your engine. I kept seeing references telling me to goto the test/dummy app. After running script/rails generate model [fields] from the root of my engine it created the appropriate model, migration rake task and i was able to run

rake my_engine:install:migrations; rake db:migrate

to run the migrations

kwbock
  • 647
  • 5
  • 13
0

You can use the generator with the engine target:

bin/engem ENGINE_NAME rails g GENERATOR