how to use seed-Fu gem in ruby - ruby-on-rails

I'm trying to work with "seed-fu" gem.I follow the document here. From that I didn't find the fixtures folder in Rails-ROOT/db/.My db folder contain developement.sqlite3, seeds,rb file.
For that I manually created fixtures under db/fixtures/users.rb.
When giving the command as "rake db:seed_fu". It shows the following in my prompt as,
== Seed from D:RAILS_ROOT/db/fixtures/users.rb
rake aborted!
uninitialized constant SeedFu::Runner::User
Tasks: TOP => db:seed_fu
(See full trace by running task with --trace)
Whats going on here..?Why I am getting this?
When running "rake db:seed_fu --trace" IT shows the following..,
** Invoke db:seed_fu (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:seed_fu
== Seed from /home/ec2-user/malar/app/db/fixtures/user.rb
rake aborted!
uninitialized constant SeedFu::Runner::User
/home/ec2-user/.rvm/gems/ruby-1.9.2-p290#a-ms/gems/seed-fu-2.2.0/lib/seed-fu/run
ner.rb:46:in `eval'
/home/ec2-user/.rvm/gems/ruby-1.9.2-p290#a-ms/gems/seed-fu-2.2.0/lib/seed-fu/run
ner.rb:46:in `eval'
/home/ec2-user/.rvm/gems/ruby-1.9.2-p290#a-ms/gems/seed-fu-2.2.0/lib/seed-fu/run
ner.rb:46:in `block (2 levels) in run_file'
/home/ec2-user/.rvm/gems/ruby-1.9.2-p290#a-ms/gems/seed-fu-2.2.0/lib/seed-fu/run
ner.rb:58:in `block in open'
/home/ec2-user/.rvm/gems/ruby-1.9.2-p290#a-ms/gems/seed-fu-2.2.0/lib/seed-fu/run
ner.rb:57:in `open'
/home/ec2-user/.rvm/gems/ruby-1.9.2-p290#a-ms/gems/seed-fu-2.2.0/lib/seed-fu/run
ner.rb:57:in `open'

From the presented details, I can't find out what's wrong with your setup but here's a screencast showing the right way to use it:
http://railscasts.com/episodes/179-seed-data

Make sure the models and the name of the seed data match. The seed file can be named whatever you like, but the seed data needs to be the same. See this blog post for an example of using Seed Fu.

Related

no implicit conversion of Hash into String Couldn't create 'API_development' database. Please check your configuration. rails aborted

when I try to create database I get below errors:
Command rails db:create --trace gives below:
no implicit conversion of Hash into String
Couldn't create 'API_development' database. Please check your configuration.
rails aborted!
TypeError: no implicit conversion of Hash into String
/mnt/c/Users/Jaydip/Documents/project/API/bin/rails:5:in `<top (required)>'
/mnt/c/Users/Jaydip/Documents/project/API/bin/spring:10:in `block in <top (required)>'
/mnt/c/Users/Jaydip/Documents/project/API/bin/spring:7:in `<top (required)>'
Tasks: TOP => db:create
(See full trace by running task with --trace)
jaydip#DESKTOP-AD7S893:/mnt/c/Users/Jaydip/Documents/project/API$ rails db:create --trace
** Invoke db:create (first_time)
** Invoke db:load_config (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:load_config
** Execute db:create
no implicit conversion of Hash into String
Couldn't create 'API_development' database. Please check your configuration.
rails aborted!
TypeError: no implicit conversion of Hash into String
/home/jaydip/.rvm/gems/ruby-3.0.0#API/gems/mysql2-0.5.0/lib/mysql2/error.rb:55:in `encode'
/home/jaydip/.rvm/gems/ruby-3.0.0#API/gems/mysql2-0.5.0/lib/mysql2/error.rb:55:in `initialize'
/home/jaydip/.rvm/gems/ruby-3.0.0#API/gems/mysql2-0.5.0/lib/mysql2/error.rb:62:in `new'
/home/jaydip/.rvm/gems/ruby-3.0.0#API/gems/mysql2-0.5.0/lib/mysql2/error.rb:62:in `new_with_args'
/home/jaydip/.rvm/gems/ruby-3.0.0#API/gems/mysql2-0.5.0/lib/mysql2/client.rb:90:in `connect'
/home/jaydip/.rvm/gems/ruby-3.0.0#API/gems/mysql2-0.5.0/lib/mysql2/client.rb:90:in `initialize'
/home/jaydip/.rvm/gems/ruby-3.0.0#API/gems/activerecord-6.1.4/lib/active_record/connection_adapters/mysql2_adapter.rb:40:in `new'
...
Tasks: TOP => db:create
Note: I am using WSL linux subsystem of windows.
Can anyone please help to resolve it ...
Update: Here is image of database.yml file
Solution : I changed mysql2 gem version 0.5.0 to 0.5.3 and error was gone.

Issue regarding running rake db:seed task

I have an existing rails project and I am using postgres database and after successful execution of bundle exec rake db:migrate command when I am going to execute the bundle exec rake db:seed command then it throws me the following error.
rake aborted!
PG::DuplicateTable: ERROR: relation "schema_migrations" already exists
I have commented out the lines where the definition of the schema_migration table creation is stored such as in the development_structure.sql and test_structure.sql files. But it is still throwing me the error.
I don't know from where the schema_migration table is being created. There is no schema_migration.rb file in my project.
Pleas help me to fix this. Thanks in advance!
This is my error log.
rake aborted!
PG::DuplicateTable: ERROR: relation "schema_migrations" already exists
: CREATE TABLE "schema_migrations" ("version" character varying(255) NOT NULL)
/home/bit/.rvm/gems/ruby-2.1.5/gems/activerecord-2.3.18/lib/active_record/connection_adapters/abstract_adapter.rb:227:in `rescue in log'
/home/bit/.rvm/gems/ruby-2.1.5/gems/activerecord-2.3.18/lib/active_record/connection_adapters/abstract_adapter.rb:204:in `log'
/home/bit/Development/app2/application/lib/core_extensions/postgresql_adapter/reconnect.rb:26:in `execute'
/home/bit/.rvm/gems/ruby-2.1.5/gems/activerecord-2.3.18/lib/active_record/connection_adapters/abstract/schema_statements.rb:109:in `create_table'
/home/bit/.rvm/gems/ruby-2.1.5/gems/activerecord-2.3.18/lib/active_record/connection_adapters/abstract/schema_statements.rb:371:in `initialize_schema_migrations_table'
/home/bit/.rvm/gems/ruby-2.1.5/gems/activerecord-2.3.18/lib/active_record/migration.rb:441:in `initialize'
/home/bit/.rvm/gems/ruby-2.1.5/gems/rails-2.3.18/lib/tasks/databases.rake:193:in `new'
/home/bit/.rvm/gems/ruby-2.1.5/gems/rails-2.3.18/lib/tasks/databases.rake:193:in `block (2 levels) in <top (required)>'
/home/bit/.rvm/gems/ruby-2.1.5/bin/ruby_executable_hooks:15:in `eval'
/home/bit/.rvm/gems/ruby-2.1.5/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => db:seed => db:seed:common => db:seed:original => db:abort_if_pending_migrations
(See full trace by running task with --trace)
If it's OK to drop your data locally, try
rake db:drop db:create db:migrate
and then seed again. I've had similar issues in the past where I deleted a migration without properly rolling it back and this was the solution.
If you need to keep it, open the rails database (rails db from terminal) and try
drop table schema_migrations
(Run the migrations with db:migrate again after this)
Edit: This has not solved the issue yet, but it seems there may be other issues that need to be factored in. OP cannot launch rails console and receives
undefined local variable or method `vars' for #<Rails::Generator::Commands::Create:0x00000001ca2578>
as the error message each time - if anyone has ideas here, please add an answer!

DEPRECATION WARNING while using bundle install

So I am trying to do bundle install . But it is throwing the below errors. What is the problem here?
bundle exec rake db:create:all
DEPRECATION WARNING: String based terminators are deprecated, please use a lambda. (called from included at /home/.gem/ruby/2.1.3/bundler/gems/authlogic-09163c7d2a9b/lib/authlogic/session/callbacks.rb:66)
DEPRECATION WARNING: String based terminators are deprecated, please use a lambda. (called from included at /home/.gem/ruby/2.1.3/bundler/gems/authlogic-09163c7d2a9b/lib/authlogic/session/callbacks.rb:67)
rake aborted!
Cannot load `Rails.application.database_configuration`:
Could not load database configuration. No such file -
/home/.gem/ruby/2.1.3/gems/railties-4.1.5/lib/rails/application/configuration.rb:105:in `database_configuration'
/home/.gem/ruby/2.1.3/gems/activerecord-4.1.5/lib/active_record/railtie.rb:43:in `block (3 levels) in <class:Railtie>'
Could not load database configuration. No such file -
/home/.gem/ruby/2.1.3/gems/railties-4.1.5/lib/rails/application/configuration.rb:105:in `database_configuration'
/home/.gem/ruby/2.1.3/gems/activerecord-4.1.5/lib/active_record/railtie.rb:43:in `block (3 levels) in <class:Railtie>'
Tasks: TOP => db:create:all => db:load_config
(See full trace by running task with --trace)
Earlier I had tried the below:
rake db:create:all
rake aborted!
Gem::LoadError: You have already activated rake 10.4.2, but your Gemfile requires rake 10.3.2. Prepending `bundle exec` to your command may solve this.
/home/.gem/ruby/2.1.3/gems/bundler-1.7.12/lib/bundler/runtime.rb:34:in `block in setup'
/home/.gem/ruby/2.1.3/gems/bundler-1.7.12/lib/bundler/runtime.rb:19:in `setup'
/home/.gem/ruby/2.1.3/gems/bundler-1.7.12/lib/bundler.rb:122:in `setup'
/home/.gem/ruby/2.1.3/gems/bundler-1.7.12/lib/bundler/setup.rb:7:in `<top (required)>'
/home/project/config/boot.rb:4:in `<top (required)>'
/home/project/config/application.rb:1:in `<top (required)>'
/home/project/Rakefile:4:in `<top (required)>'
LoadError: cannot load such file -- bundler/setup
/home/project/config/boot.rb:4:in `<top (required)>'
/home/project/config/application.rb:1:in `<top (required)>'
/home/project/Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)
$ bundle exec rake db:create:all
DEPRECATION WARNING: String based terminators are deprecated, please use a lambda. (called from included at /home/.gem/ruby/2.1.3/bundler/gems/authlogic-09163c7d2a9b/lib/authlogic/session/callbacks.rb:66)
DEPRECATION WARNING: String based terminators are deprecated, please use a lambda. (called from included at /home/.gem/ruby/2.1.3/bundler/gems/authlogic-09163c7d2a9b/lib/authlogic/session/callbacks.rb:67)
rake aborted!
Cannot load `Rails.application.database_configuration`:
Could not load database configuration. No such file -
/home/.gem/ruby/2.1.3/gems/railties-4.1.5/lib/rails/application/configuration.rb:105:in `database_configuration'
/home/.gem/ruby/2.1.3/gems/activerecord-4.1.5/lib/active_record/railtie.rb:43:in `block (3 levels) in <class:Railtie>'
Could not load database configuration. No such file -
/home/.gem/ruby/2.1.3/gems/railties-4.1.5/lib/rails/application/configuration.rb:105:in `database_configuration'
/home/.gem/ruby/2.1.3/gems/activerecord-4.1.5/lib/active_record/railtie.rb:43:in `block (3 levels) in <class:Railtie>'
Tasks: TOP => db:create:all => db:load_config
(See full trace by running task with --trace)
You are trying to run "rake db:create:all" which would create your database but as error states - it seems you don't have your config/database.yml file. It's a configuration file that tells rails how to connect to your database. You can read more about it here.
If you really want to run bundle install, just use "bundle install" command instead. This will install all gems listed in your Gemfile.
If you will get problems with rake version conflicts, check out this stack overflow question.
It seems you have no config/database.yml file in your project's directory.
Why I think so? Follow me ...
Could not load database configuration. No such file -
/home/.gem/ruby/2.1.3/gems/railties-4.1.5/lib/rails/application/configuration.rb:105:in `database_configuration'
Ok, let's take a look at this code where we have error:
yaml = Pathname.new(paths["config/database"].existent.first || "")
config = if yaml.exist?
require "yaml"
require "erb"
YAML.load(ERB.new(yaml.read).result) || {}
elsif ENV['DATABASE_URL']
# Value from ENV['DATABASE_URL'] is set to default database connection
# by Active Record.
{}
else
raise "Could not load database configuration. No such file - #{yaml}"
end
As you can see - if no such file or ENV variable then rails throws error.

"Command failed with status ()" when precompiling assets

I am having similiar problems like a lot of users when compiling assets on their productive box. The only difference is that I can't get any hint out of the trace to solve the problem.
rake assets:precompile RAILS_ENV=production --trace
** Invoke assets:precompile (first_time)
** Execute assets:precompile
/usr/local/rbenv/versions/1.9.3-p362/bin/ruby /usr/local/rbenv/versions/1.9.3-p362/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace
** Invoke assets:precompile:all (first_time)
** Execute assets:precompile:all
** Invoke assets:precompile:primary (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:primary
rake aborted!
Command failed with status (): [/usr/local/rbenv/versions/1.9.3-p362/bin/r...]
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/file_utils.rb:53:in `block in create_shell_runner'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/file_utils.rb:45:in `call'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/file_utils.rb:45:in `sh'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/file_utils_ext.rb:39:in `sh'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/file_utils.rb:80:in `ruby'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/file_utils_ext.rb:39:in `ruby'
/home/app/application/ruby/1.9.1/gems/actionpack-3.2.12/lib/sprockets/assets.rake:12:in `ruby_rake_task'
/home/app/application/ruby/1.9.1/gems/actionpack-3.2.12/lib/sprockets/assets.rake:21:in `invoke_or_reboot_rake_task'
/home/app/application/ruby/1.9.1/gems/actionpack-3.2.12/lib/sprockets/assets.rake:29:in `block (2 levels) in <top (required)>'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/task.rb:205:in `call'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/task.rb:205:in `block in execute'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/task.rb:200:in `each'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/task.rb:200:in `execute'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/task.rb:158:in `block in invoke_with_call_chain'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/task.rb:151:in `invoke_with_call_chain'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/task.rb:144:in `invoke'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/application.rb:116:in `invoke_task'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/application.rb:94:in `block (2 levels) in top_level'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/application.rb:94:in `each'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/application.rb:94:in `block in top_level'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/application.rb:133:in `standard_exception_handling'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/application.rb:88:in `top_level'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/application.rb:66:in `block in run'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/application.rb:133:in `standard_exception_handling'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/application.rb:63:in `run'
/usr/local/rbenv/versions/1.9.3-p362/bin/rake:32:in `<main>'
Tasks: TOP => assets:precompile
There is effectively no status code, just the fail. It also does not make any difference if I call rake directly or via bundle exec.
About the environment
debian squeeze box with a global rbenv installation (/usr/local/rbenv like you can see from the trace). Ruby 1.9.3 2012-12-25 patchlevel 362.
Any hints / ideas on this?
I am going to answer this myself because I could solve it more or less. If someone has additions, don't hesitate to write an own answer or comment this answer/question.
What I've found out so far:
If you play around with assets:precompile by e.g just compiling the primary assets (assets:precompile:primary) or explicitly calling assets:precompile:all you might end up with a hint about the source of your problem. In my case, I ran into Errno::EACCES on both public/ and tmp/. Somehow that was not displayed, so make sure your user has full rights to create/delete files and folders there.
In my case, it worked sometimes because I've shut down the rails app and precompiled while it was down. Since precompiling allocates a lot of memory, I did some trial and error and eventually got the known Killed message when rake tries to execute asstes:precompile:primary. The task simply was killed because of using too much memory.
Another problem was that sprockets could not find bootstrap to put it into the assets pipeline on precompilation. Moving gem 'bootstrap' outside of group :assets solved this. This was also something I got hinted to when I played around with the commands.
The best way to solve – or better: work around – this problem is to simply compile your assets locally. Just throw a rake assets:precompile RAILS_ENV=development into your terminal and then deploy public/assets. Remember to delete that folder in your development environment after deploying it or you will end up debugging on why your changes on app/assets/* are not taking effect in development. At least that works for me(tm).
Alternatively, growing your swap partition may also work. However, compilation on a VPS where you need to use swap may take its while, so I'd stick to the local way.
I also had same issue.
I fixed it by adding swap(in my case 1gb for 512RAM available on my server)
Try running htop while your assets are compiling to see if you run out of RAM. Adding swap fixed it for me.
See this guide for adding swap: https://www.digitalocean.com/community/articles/how-to-add-swap-on-ubuntu-12-04

Cucumber rake cucumber:ok - errors

I am getting errors when I run: rake cucumber:ok
Can you please tell me how to fix the following error?
Gem versions I am using:
rails Rails 3.0.8.rc4
rspec 2.6.3
cucumber 0.10.3
Errors when I run: rake cucumber:ok
[ticketee (master)]$ rake cucumber:ok
/Users/duser/.rvm/rubies/ruby-1.9.2-p180/bin/ruby -S bundle exec cucumber --profile default
Using the default profile...
features/creating_projects.feature: Lexing error on line 12: '%%_FEATURE_END_%%'. See http://wiki.github.com/cucumber/gherkin/lexingerror for more information. (Gherkin::Lexer::LexingError)
/Users/duser/.rvm/gems/ruby-1.9.2-p180/gems/gherkin-2.3.10/lib/gherkin/lexer/i18n_lexer.rb:23:in `scan'
/Users/duser/.rvm/gems/ruby-1.9.2-p180/gems/gherkin-2.3.10/lib/gherkin/lexer/i18n_lexer.rb:23:in `scan'
/Users/duser/.rvm/gems/ruby-1.9.2-p180/gems/gherkin-2.3.10/lib/gherkin/parser/parser.rb:31:in `parse'
/Users/duser/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-0.10.3/lib/cucumber/feature_file.rb:37:in `parse'
/Users/duser/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-0.10.3/lib/cucumber/runtime/features_loader.rb:28:in `block in load'
/Users/duser/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-0.10.3/lib/cucumber/runtime/features_loader.rb:26:in `each'
/Users/duser/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-0.10.3/lib/cucumber/runtime/features_loader.rb:26:in `load'
/Users/duser/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-0.10.3/lib/cucumber/runtime/features_loader.rb:14:in `features'
/Users/duser/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-0.10.3/lib/cucumber/runtime.rb:132:in `features'
/Users/duser/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-0.10.3/lib/cucumber/runtime.rb:45:in `run!'
/Users/duser/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-0.10.3/lib/cucumber/cli/main.rb:43:in `execute!'
/Users/duser/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-0.10.3/lib/cucumber/cli/main.rb:20:in `execute'
/Users/duser/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-0.10.3/bin/cucumber:14:in `<top (required)>'
/Users/duser/.rvm/gems/ruby-1.9.2-p180/bin/cucumber:19:in `load'
/Users/duser/.rvm/gems/ruby-1.9.2-p180/bin/cucumber:19:in `<main>'
rake aborted!
Command failed with status (1): [/Users/duser/.rvm/rubies/ruby-1.9.2-p18...]
Tasks: TOP => cucumber:ok
(See full trace by running task with --trace)
[ticketee (master)]$
Contents of features/creating_projects.feature
Feature: Creating projects
In order to have projects to assign tickets to
As a user I want to create them easily
Scenarios: Creating a project
Given I am on the homepage
When I follow "New Project"
And I fill in "Name" with "Text Mate 2"
And I press "Create Project"
Then I should see "Project has been created"
I figured out the problem:
In the features/creating_projects.feature file, I had "Scenarios:", and it should be "Scenario:". This is the reason for the errors.
You have a lexing error on line 12 of features/creating_projects.feature and its most likely at the end of the feature definition. Are you using the correct syntax in the file?

Resources