开发者

Seeding database from engine root fails to locate db/seeds.rb

After creating a new Rails 3.1 gem plugin via:

rails plugin new core --full

I am trying to seed the database with:

rake db:seed

I am running into the following error:

rake aborted!
can't convert nil into String

Moving the seeds.rb file into the test/dummy/db开发者_运维技巧 directory seems to resolve the problem. Is there any way to let the db:seed task know what the current working directory is, or where to find the seeds.rb file? The ideal solution would be to keep seeds.rb within my engines db directory


I got this error when I made a mistake naming my seed file "seed.rb", not "seeds.rb". Hope, this helps.


Try creating your engine as

rails plugin new core --full --mountable

You should now be able to do rake db:migrate from your engine root. If it's not a mountable engine, since the generators would typically deploy to your app (in this case test/dummy or spec/dummy) it makes sense that the rake task would be run from the host application.


I solved this by creating a seeds.rb in my dummy/db directory. In the seeds.rb file I created, I just added:

require File.expand_path('../../../../db/seeds.rb', __FILE__)

This basically extends and runs the seeds.rb file in the engines db directory.

Please Note

  1. I am using both --full and --mountable and rake db:seed did not work (plus various other things)
  2. I am using rspec for my tests, so my dummy is in the spec/dummy directory of the engine
  3. I modified my rake and rails so that I could get rspec working

useful posts I have found

  1. rails 3.1 engines with rspec

Hope this helps

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜