Rails engine / How to use seed?

jakobk picture jakobk · Oct 10, 2012 · Viewed 6.9k times · Source

I have created a Rails Engine. I am having trouble using the seed command, if I run rake db:seed I get the error: "uninitialized constant".

In the engine, I got a seeds.rb:

Page.create(:title => 'Frontpage', :order => '1')

Then in my dummy app I got a seeds.rb with

cms::Engine.load_seed   

(cms being the name of the engine) -- I got an error now though, that "uninitialized constant ". How do I reference the constant from the dummy app?

Answer

jakobk picture jakobk · Oct 10, 2012

Ok, got it! - the answer is:

In the engine, add a seeds.rb in the db folder, prepend the app name to each constant, like so:

Cms::Page.create(:title => 'Frontpage', :order => '1')

In the dummy app, or the app where you are adding your engine, add a seeds.rb to the db folder with:

Cms::Engine.load_seed

and run:

rake db:seed 

in the terminal.