bundle exec rake snorby:setup - error rake aborted! invalid hash - ruby

While executing below command to setup the snorby on ruby on rails, i get the error: rake aborted! invalid hash. Pls help
#bundle exec rake snorby:setup
#Jammit Warning: Asset compression disabled -- Java unavailable.
No time_zone specified in snorby_config.yml; detected time_zone: Asia/Kolkata
750d6d911891ab576bdbc6b1c4dc5ecf73cb95fd145ab7b16194636094daa3b4ba42b01c05d991c8c174919162e00152a129c645b1e0508850042cf224f165af
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1007 (HY000) at line 1: Can't create database 'snorby'; database exists
[datamapper] Finished auto_upgrade! for :default repository 'snorby'
rake aborted!
invalid hash
Tasks: TOP => db:seed
(See full trace by running task with --trace)
Below are the versions currently used:
#ruby 1.9.3p551 (2014-11-13 revision 48406) [x86_64-linux]
#Bundler version 1.9.3
#Ubuntu 20.04 LTS (focal)

Modifying the entries in seeds.rb file as given below, the error has been resolved. In the seeds.rb changed the line for Default user setup from
User.create(:name => 'Administrator', :email => 'snorby#snorby.org', :password => 'snorby', :password_confirmation => 'snorby', :admin => true) if User.all.blank?
To
User.create(:name => 'Administrator', :email => 'snorby#snorby.org', :encrypted_password => 'snorby', :password_confirmation => 'snorby', :admin => true) if User.all.blank?
i.e the :password was changed to :encrypted_password

Related

Nothing happened when i run db:seed on Heroku

My app is made by Sinatra any everything working fine on my local server.
But when i deployed to Heroku and i ran this command
$ heroku run rake db:seed
Nothing happened even this command worked fine.
$ heroku run rake db:migrate
So this is my seed code
require_relative '../app/models/question'
require_relative '../app/models/answer'
require_relative '../app/models/user'
require 'faker'
class TaskSeed
def self.faker
20.times do
Question.create(
:content => Faker::Lorem.sentence(200, true),
:headline => Faker::Lorem.sentence,
:user_id => Faker::Number.between(1, 10)
)
end
40.times do
Answer.create(
:content => Faker::Lorem.sentence(20, true),
:headline => Faker::Lorem.sentence,
:user_id => Faker::Number.between(1, 10),
:question_id => Faker::Number.between(1, 10)
)
end
20.times do
User.create(
:username => Faker::Internet.user_name,
:email => Faker::Internet.email,
:encrypted_password => Faker::Internet.password(10, 20)
)
end
vote_type_arr = ['up','down']
50.times do
QuestionVote.create(
:type => vote_type_arr[rand(0..1)],
:question_id => Faker::Number.between(1, 20)
)
end
end
end
TaskSeed.faker
Anyone know how to fix this?
Thanks!
i am using PostgreSQL as my local since the project was made.
If your local database is clean(no testing data), then you could try heroku db:push
If you are using the default PostgreSQL, try
heroku pg:reset
heroku rake db:seed

Paperclip & Fog: Getting 'NameError (uninitialized constant Fog):'

Paperclip/Fog works on my local machine (Mac 10.8.4), but fails on server (Ubuntu 10.04 LTS). We have been using paperclip fine with local storage, but last night, migrated to cloud files and I'm getting this: 'uninitialized constant Fog' error.
Console Output:
Started PUT "/projects/car-tournament-of-champions-catoc" for 70.112.118.118 at 2013-08-19 06:44:57 +0000
Processing by ProjectsController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"dwYOstjhuj2npLioC2rcXBKQ4lhGMlLt8s+epBm5vzk=", "project"=>{"name"=>"Car Tournament of Champions™ (CATOC™)", "headline"=>"Introducing true audiophile sound to the automotive environment", "about"=>"Car Audio Tournament of Champions (CATOC) is the world leader in premium sound system evaluation and marketing", "project_image"=>#<ActionDispatch::Http::UploadedFile:0x000000064a96c8 #original_filename="CATOC_MAIN_K.jpg", #content_type="image/jpeg", #headers="Content-Disposition: form-data; name=\"project[project_image]\"; filename=\"CATOC_MAIN_K.jpg\"\r\nContent-Type: image/jpeg\r\n", #tempfile=#<File:/tmp/RackMultipart20130819-4418-97i2l5>>, "category_id"=>"1", "paypal_email"=>"pre-registration#catoc-cca.com", "extra_amount"=>"0", "extend_days"=>"0"}, "button"=>"", "id"=>"car-tournament-of-champions-catoc"}
Completed 500 Internal Server Error in 12ms
NameError (uninitialized constant Fog):
app/controllers/projects_controller.rb:387:in `block in update'
app/controllers/projects_controller.rb:386:in `update'
Gemfile:
gem 'rails', '3.2.3' #ruby 1.9.3-p194
gem 'fog'
gem 'paperclip', '~> 3.0'
application.rb file:
config.paperclip_defaults = {
:path => "images/:class/:id/:attachment/:style/img_:fingerprint",
:storage => :fog,
:fog_credentials => {
:provider => 'Rackspace',
:rackspace_username => '<rackspace userid>',
:rackspace_api_key => '<rackspace api key>',
:region => 'dfw',
:persistent => false
},
:fog_directory => "prod_image_container",
:fog_public => true,
:fog_host => "http://c8d0f182112c0c3e585e-d37a976c417d5d9c71ba0df711c60fa4.r4.cf1.rackcdn.com"
}
project.rb file:
class Project < ActiveRecord::Base
attr_accessible :project_image
has_attached_file :project_image, :styles => {:medium => "260x180#"}
end
Can you verify that you have installed the fog gem as well as the version?
You should be able to do this by executing bundle show.

How do you debug opscode chef / ruby errors?

I'm a python guy and struggling to make sense of ruby stacktraces. I'd appreciate if anyone can tell me a systematic method to get to the bottom of what is causing a message like this. Running Opscode 11.4. I thought its probably due to an outdated opscode cookbook, so updated ark to 0.0.17 - the latest. However the problem persists. I thought perhaps it was a dependancy of another cookbook. It is, elasticsearch, however no version is specified. In any case this method seems like guess work however there is not a clear stack trace of where the underlaying problem is. What is the correct way to action such a message?
Synchronizing Cookbooks:
- users
- ark
- elasticsearch
- openssl
- sudo
- yum
- ohai
- munin
- bluepill
- runit
- postgresql
- build-essential
- apt
- git
- nginx
Compiling Cookbooks...
================================================================================
Recipe Compile Error in /var/chef/cache/cookbooks/ark/libraries/resource_ark.rb
================================================================================
NoMethodError
-------------
undefined method `attribute' for Chef::Resource::Ark:Class
Cookbook Trace:
---------------
/var/chef/cache/cookbooks/ark/libraries/resource_ark.rb:37
Relevant File Content:
----------------------
/var/chef/cache/cookbooks/ark/libraries/resource_ark.rb:
30: #allowed_actions.push(:install, :dump, :cherry_pick, :put, :install_with_make, :configure, :setup_py_build, :setup_py_install, :setup_py)
31: #action = :install
32: #provider = Chef::Provider::Ark
33: end
34:
35: attr_accessor :path, :release_file, :prefix_bin, :prefix_root, :home_dir, :extension, :version
36:
37>> attribute :owner, :kind_of => String, :default => 'root'
38: attribute :group, :kind_of => [String, Fixnum], :default => 0
39: attribute :url, :kind_of => String, :required => true
40: attribute :path, :kind_of => String, :default => nil
41: attribute :full_path, :kind_of => String, :default => nil
42: attribute :append_env_path, :kind_of => [TrueClass, FalseClass], :default => false
43: attribute :checksum, :regex => /^[a-zA-Z0-9]{64}$/, :default => nil
44: attribute :has_binaries, :kind_of => Array, :default => []
45: attribute :creates, :kind_of => String, :default => nil
46: attribute :release_file, :kind_of => String, :default => ''
[2013-02-25T00:19:30+00:00] ERROR: Running exception handlers
[2013-02-25T00:19:30+00:00] FATAL: Saving node information to /var/chef/cache/failed-run-data.json
[2013-02-25T00:19:30+00:00] ERROR: Exception handlers complete
Chef Client failed. 0 resources updated
[2013-02-25T00:19:30+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2013-02-25T00:19:30+00:00] FATAL: NoMethodError: undefined method `attribute' for Chef::Resource::Ark:Class
Seems that the community site version 0.0.17 is not the same as the current head even though they have the same version number. Installing source from github https://github.com/opscode-cookbooks/ark/commit/b8c4aaf17d6e88aa857af6b2038eb0dba9981c0b solved the problem.

Sinatra/ActiveRecord can't handle simultaneous requests?

This is my first Sinatra project and I'm pretty late in and I'm realizing that when make multiple requests at once that use ActiveRecord that I run into problems. If I only make one request, each one works on its own. But when I call both at once, I get failure.
So far I've narrowed it down to the problem being two ActiveRecord requests simultaneously. Maybe I'm not setting up ActiveRecord correctly? I use PostgreSQL because Heroku uses it, and am no inclined to change. (The issue happens on Heroku, too.)
Here's the log:
192.168.1.113 - - [30/Sep/2012:10:33:00 MDT] "GET /version/current?platform=android HTTP/1.1" 200 33
- -> /version/current?platform=android ActiveRecord::StatementInvalid - NoMethodError: undefined method `fields' for nil:NilClass: SELECT "rankings".* FROM "rankings" WHERE "rankings"."user_id" = 1 LIMIT 1:
/Users/zablanc/.rvm/gems/ruby-1.9.3-head#emm/gems/activerecord-3.2.7/lib/active_record/connection_adapters/postgresql_adapter.rb:667:in `block in exec_query'
...
Warning! Rack::Session::Cookie data size exceeds 4K.
Warning! Rack::Session::Cookie failed to save session. Content dropped.
192.168.1.113 - - [30/Sep/2012:10:33:01 MDT] "GET /badges/all HTTP/1.1" 200 311
- -> /badges/all
192.168.1.113 - - [30/Sep/2012:10:33:01 MDT] "GET /moves/ranking/all HTTP/1.1" 500 166185
- -> /moves/ranking/all
I have no idea how to shut up those cookie warnings, tho they seem to have no effect on the app. Here's how I configure my app (in a config file I require from the main script):
enable :logging
use ActiveRecord::ConnectionAdapters::ConnectionManagement
use Rack::Session::Cookie, :key => 'rack.session',
:path => '/',
:expire_after => 31_536_000, # In seconds
:secret => 'jeowkfj...secret...kjn5'
ActiveRecord::Base.include_root_in_json = false
def establish_connection(url)
db = URI.parse(url)
ActiveRecord::Base.establish_connection(
:adapter => db.scheme == 'postgres' ? 'postgresql' : db.scheme,
:host => db.host,
:port => db.port,
:username => db.user,
:password => db.password,
:database => db.path[1..-1],
:encoding => 'utf8'
)
end
configure :development do
establish_connection('postgres://postgres:postgres#localhost:5432/emm')
end
configure :test do
establish_connection('postgres://postgres:postgres#localhost:5432/emm-test')
end
configure :production do
establish_connection(ENV['DATABASE_URL'])
end
I'm guessing I'm not setting up ActiveRecord right, but I think it's just like the tutorials I've seen. What gives?
Sounds like you are using threads but have some non-thread-safe code in your application.
Which webserver are you using, which middleware are you using, which postgresql gem are you using, did you check to see that all your gems are thread-safe?

Tests within Gem need to test migration generator and apply migrations for tests

I'm working on a Gem that contains a migration generator and a bunch of models, classes, etc that utilize the tables created as part of the migration.
Although testing the migration generator itself is easy enough - there's loads of tutorials around for getting that done, what i'm trying to work out is how to actually run the migration on the test DB so I can later test how the gem interacts with the test data?
Since the gem doesn't have a schema.rb, I wasn't sure how to go about doing it.
This is how I run migrations in code;
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
ActiveRecord::Migration.verbose = false
#migration = Class.new(ActiveRecord::Migration) do
def change
create_table :users, :force => true do |t|
t.string :roles_mask
end
create_table :user_without_roles, :force => true do |t|
t.string :roles_mask
end
create_table :user_without_role_masks, :force => true do |t|
end
end
end
#migration.new.migrate(:up)
If you have a string containing your generated migration you could do something like this in your test setup;
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
ActiveRecord::Migration.verbose = false
# Or however you intend to grab the output of the migration generator
migration_string = ERB.new(File.read(<file name here>)).result
migration = Class.new(ActiveRecord::Migration)
migration.class_eval(migration_string)
migration.new.migrate(:up)
That should give you a migrated database using the migration you've generated.
You can do something like this:
I am going to assume you're using ActiveRecord. So in your test helper you should setup a in-memory database:
require 'active_record'
# Connection must be establised before anything else
ActiveRecord::Base.establish_connection(
:adapter => defined?(JRUBY_VERSION) ? 'jdbcsqlite3' : 'sqlite3',
:database => ':memory:'
)
Then invoke the rake task within your test. This would look something like:
require 'rake'
requie File.expand_path('../Rakefile', __FILE__) # you'll need to modify this path to actually point to the Rakefile
Rake::Task['db:migrate'].invoke
The rake taks invocation is untested, but that should point you in the right direction.
The other option would be to just run the command:
%x{rake db:migrate}

Resources