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
I am using both --full and --mountable and rake db:seed did not work (plus various other things)
I am using rspec for my tests, so my dummy is in the spec/dummy directory of the engine
I modified my rake and rails so that I could get rspec working
useful posts I have found
rails 3.1 engines with rspec
Hope this helps
Related
I am deploying a heroku app.
I'm running ubuntu 14.04LTS
After git cloning, I copied the migrate files from my previous project and ran:
bin/rake db:create db:migrate
Everything seemed to be going well until I checked the models folder.
why does rake not create models? How do I fix this?
There is a typo here: it is db:migrate (instead of bd:migrate). Also, rake does not create models.
To create models along with migrations, use rails generate model MyModel.
On the other hand, if all your tables are created using migrations, then just create the model files manually in the app/models folder.
I have stated working on neo4j with rails using the gem 'neo4j', I want to seed some data in neo4j database. But whenever I am trying to do rake db:seed, it says
rake aborted!
Don't know how to build task 'db:seed'
I have checked all the rake tasks using rake -T, and there is no rake db:seed.
Does any one have any idea?
The Neo4j gem doesn't have a seed command. The command you're trying to use is provided by ActiveRecord. We'd love to add this functionality in, though, and if you'd like to help, we'd gladly accept a PR and/or contribute to the process. For now, open up an issue at https://github.com/neo4jrb/neo4j/issues and we can add it to the roadmap.
Finally got the solutions.
Create a file seed.rake under lib/tasks and put the code
namespace :db do
desc 'Load the seed data from db/seeds.rb'
task :seed => :environment do
seed_file = File.join(Rails.root, 'db', 'seeds.rb')
load(seed_file) if File.exist?(seed_file)
end
end
Check apps root directory, is there a Rakefile?
Make a file with name "Rakefile" and enter these line
"#!/usr/bin/env rake
require File.expand_path('../config/application', FILE)
APP_NAME::Application.load_tasks
As others mentioned before, rails db:seed is a built-in feature backed by ActiveRecord. Assuming you are using neo4jrb without ActiveRecord, you won't be able to use this command to seed database any more.
However, you can use seedbank gem to recover this ability.
It does not depend on ActiveRecord like seed_fu and other seeding gems do. So it will work just fine with neo4jrb.
The process is rather simple.
put seedbank in your Gemfile and bundle install.
create directory db/seeds/
create a seeds file under the db/seeds/ directory
for example
#db/seeds/show.seeds.rb
Show.create(name: "Better Call Saul", producer: "Vince Gilligan")
run rake db:seed:show
We want to create session table in our rails (3.2.9) engine. But rake db:sessions:create does not work in rails engine root directory (only works under the dummy directory). Is there way to create sessions in rails engine? Or can we add rake db:sessions:create in Rakefile for the engine so we can use the rake command?
Thanks for the help.
As an engine is not a rails app, it's not linked with a database and you cannot create the session table, only add a migration for that.
Couldn't you just copy the migration from dummy to the migrations folder of your engine ?
I am creating a brand new full gem plugin using Rails 3.1.0 on ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux]. I am having trouble with the schema and fixtures not being loaded for running rake test. Following are the steps I am taking:
Create the plugin:
rails plugin new core --full
From the plugin, generate a new scaffold:
rails g scaffold user
Run the db create and migrate:
rake db:create
rake db:migrate
Run the tests:
rake test
When running the functional tests, I am receiving a set of error like the following from the controller tests:
1) Error:
test_should_create_user(UsersControllerTest):
NoMethodError: undefined method `users' for #<UsersControllerTest:0x00000003babca8>
This error seems to stem from the fact that the test doesn't seem to understand the fixture call. It doesn't look like the test db is getting the schema loaded or having the fixtures loaded. Is this expected behavior? Is there something I'm missing in this scenario? All the fixtures are there. Is there some process I need to follow to get these tests to run correctly?
OK, I think I've made some progress. It looks like I can resolve it with the following changes.
I've added the following to test_helper:
#Run any available migration
ActiveRecord::Migrator.migrate 'up'
# Set fixtures root
ActiveSupport::TestCase.fixture_path=(File.expand_path("../fixtures", __FILE__))
ActiveSupport::TestCase.fixtures :all
This allows the test environment to find my fixtures outside of the dummy application.
After this change, I was still having an issue where the test database was not being prepared for the test. I resolved this by dropping into the test/dummy directory and running:
rake db:test:prepare
After this, I am able to run "rake test" successfully. It's somewhat a pain to have to drop in to the dummy app to prepare the db. There has to be a way around this. Any suggestions?
can't seem to get my seeds.rb file to run through the command "rake db:seed". I'm using netbeans and I'm a beginner to rails, so I could be doing something really simple and stupid =/. I know you're meant to put your seeds.rb file in the db directory but netbeans doesn't seem to have one or might have renamed it... any help out there?
The rake task db:seed will load the Rails environment and then load and execute the file db/seeds.rb.
If you do not have a file db/seeds.rb, then make one (and if necessary make the db directory too).