Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails engine / How to use seed?

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?

like image 268
jakobk Avatar asked Oct 10 '12 14:10

jakobk


1 Answers

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.

like image 153
jakobk Avatar answered Sep 21 '22 18:09

jakobk