Mongoid3 + FactoryGirl Incompatible? - devise

I just upgrade to Mongoid3 and Im getting a TON of these errors:
TypeError:
can't convert String into Integer
The issue is always when Im trying to build a model that belongs_to another model and I assign the referenced model:
#entry = FactoryGirl.create(:entry_image, user_id: #user.id, day: 18, month: 6)
It seems to be the "user_id: #user.id" part. Ive tried:
#entry = FactoryGirl.build(:entry_image, day: 18, month: 6)
#entry.user = #user
#entry.save
Same error every time.
Here is the factory file:
FactoryGirl.define do
factory :user do
name 'Test User'
email 'example#example.com'
password 'please'
password_confirmation 'please'
pin '1234'
default_time_zone 'America/New_York'
end
...
Im using devise, here is the controller macro we run:
module ControllerMacros
def login_user
before(:each) do
#request.env["devise.mapping"] = Devise.mappings[:user]
#user = FactoryGirl.create(:user)
#user.confirm! # or set a confirmed_at inside the factory. Only necessary if you are using the confirmable module
sign_in #user
end
end
end
Here is the full stack trace:
> 1.9.3p194 :016 > user = User.all[0]
=> #<User _id: 503e9c807adf9d6551000001, _type: nil, email: "joe#email.com", encrypted_password: "$5a$10$Mt1kx/TtbDma4gVtcTLdLeeP6tcSiF2AJkjeJmv73/U5OWF.M34v.", remember_created_at: 2012-08-29 23:30:17 UTC, sign_in_count: 3, current_sign_in_at: 2012-08-29 23:30:17 UTC, last_sign_in_at: 2012-08-29 22:49:57 UTC, current_sign_in_ip: "127.0.0.1", last_sign_in_ip: "127.0.0.1", s3_access_key: #<Moped::BSON::Binary type=:generic length=24>, s3_secret_key: #<Moped::BSON::Binary type=:generic length=48>, pin: nil, default_time_zone: "America/New_York", name: "Joe Smith">
1.9.3p194 :017 > e = FactoryGirl.create(("entry_image").to_s, user_id: user.id, items: [ FactoryGirl.build(:image, user_id: user.id) ])
TypeError: can't convert String into Integer
from /Users/lee/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/set.rb:185:in `include?'
from /Users/lee/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/set.rb:185:in `include?'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.5/lib/mongoid/callbacks.rb:140:in `block (3 levels) in cascadable_children'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.5/lib/mongoid/callbacks.rb:139:in `each'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.5/lib/mongoid/callbacks.rb:139:in `block (2 levels) in cascadable_children'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.5/lib/mongoid/relations/accessors.rb:103:in `without_autobuild'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.5/lib/mongoid/callbacks.rb:133:in `block in cascadable_children'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.5/lib/mongoid/callbacks.rb:131:in `each_pair'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.5/lib/mongoid/callbacks.rb:131:in `cascadable_children'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.5/lib/mongoid/callbacks.rb:95:in `run_callbacks'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/activemodel-3.2.0/lib/active_model/validations/callbacks.rb:53:in `run_validations!'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/activemodel-3.2.0/lib/active_model/validations.rb:179:in `valid?'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.5/lib/mongoid/validations.rb:78:in `valid?'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/activemodel-3.2.0/lib/active_model/validations.rb:187:in `invalid?'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.5/lib/mongoid/persistence/insertion.rb:22:in `prepare'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.5/lib/mongoid/persistence/operations/insert.rb:26:in `persist'
... 4 levels...
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/factory_girl-4.0.0/lib/factory_girl/evaluation.rb:15:in `[]'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/factory_girl-4.0.0/lib/factory_girl/evaluation.rb:15:in `create'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/factory_girl-4.0.0/lib/factory_girl/strategy/create.rb:12:in `block in result'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/factory_girl-4.0.0/lib/factory_girl/strategy/create.rb:9:in `tap'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/factory_girl-4.0.0/lib/factory_girl/strategy/create.rb:9:in `result'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/factory_girl-4.0.0/lib/factory_girl/factory.rb:42:in `run'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/factory_girl-4.0.0/lib/factory_girl/factory_runner.rb:23:in `block in run'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.0/lib/active_support/notifications.rb:125:in `instrument'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/factory_girl-4.0.0/lib/factory_girl/factory_runner.rb:22:in `run'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/factory_girl-4.0.0/lib/factory_girl/strategy_syntax_method_registrar.rb:19:in `block in define_singular_strategy_method'
from (irb):17
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.0/lib/rails/commands/console.rb:47:in `start'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.0/lib/rails/commands/console.rb:8:in `start'
from /Users/lee/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.0/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

Related

Rails ActiveRecard validation fail

I'm having some trouble saving a model
class AmazonMovie < ActiveRecord::Base
attr_accessible :asin_buy, :asin_rent, :movie_id, :on_prime, :on_prime_prev, :price_buy, :price_buy_prev, :price_rent, :price_rent_prev, :url, :updated_at, :created_at
belongs_to :movie
has_many :amazon_movie_changes, :dependent => :destroy
validates :movie_id, presence: true, uniqueness: true
AWS_QPS_THRESHOLD = 1.0
before_create :init
def init
self.on_prime_prev = false
end
def update_changes
...
There's another class
class AmazonMovieChange < ActiveRecord::Base
attr_accessible :amazon_movie_id, :buy_change, :movie_id, :on_prime, :on_prime_prev, :price_buy, :price_buy_prev, :price_rent, :price_rent_prev, :prime_change, :rent_change
belongs_to :movie
belongs_to :amazon_movie
validates_presence_of :movie_id, :amazon_movie_id
....
When I created a model like the following:
=> #<AmazonMovie id: nil, movie_id: 16918, asin_buy: "B00FSTCUGA", price_buy: 7.99, price_buy_prev: nil, asin_rent: "B00FST7SX0", price_rent: 3.99, price_rent_prev: nil, on_prime: false, on_prime_prev: false, url: "http://www.amazon.com/Strongman-Stanless-Steel/dp/B...", created_at: nil, updated_at: nil>
I'm getting the following save failure:
ActiveRecord::RecordInvalid: Validation failed: Amazon movie changes is invalid
from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.8/lib/active_record/validations.rb:56:in `save!'
from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.8/lib/active_record/attribute_methods/dirty.rb:33:in `save!'
from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.8/lib/active_record/transactions.rb:246:in `block in save!'
from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.8/lib/active_record/transactions.rb:295:in `block in with_transaction_returning_status'
from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.8/lib/active_record/transactions.rb:208:in `transaction'
from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.8/lib/active_record/transactions.rb:293:in `with_transaction_returning_status'
from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.8/lib/active_record/transactions.rb:246:in `save!'
from (irb):145
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.8/lib/rails/commands/console.rb:47:in `start'
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.8/lib/rails/commands/console.rb:8:in `start'
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.8/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
UPDATE:
I realized by removing the before_create :init this model saves without errors. My original intent was to default this field as false instead of NULL. Is there something wrong in my syntax? Or this is not the right way to default a field?

ckeditor in Rails 3.0.9

i have my project with Rails 3.0.9 and i added the CKeditor 3.6.3, in development works fine, and in Staging in Heroku works fine too, but in Production crash the app.
This are the configuration i have to production:
config/application.rb
config.autoload_paths += %W(#{config.root}/app/models/ckeditor)
config/environments/production.rb
#config.assets.precompile += Ckeditor.assets
I have commented the line because config.assets is not available until Rails 3.1, but i don't want to upgrade Rails in this moment.
app/models/ckeditor/attachment_file.rb
class Ckeditor::AttachmentFile < Ckeditor::Asset
has_attached_file :data,
:storage => :s3,
:s3_credentials => "#{Rails.root}/config/s3.yml",
:path => ":attachment/:id/:style.:extension",
:url => ":s3_domain_url"
validates_attachment_size :data, :less_than => 100.megabytes
validates_attachment_presence :data
def url_thumb
#url_thumb ||= Ckeditor::Utils.filethumb(filename)
end
end
app/models/ckeditor/picture.rb
class Ckeditor::Picture < Ckeditor::Asset
has_attached_file :data, :styles => { :content => '800>', :thumb => '118x100#' },
:storage => :s3,
:s3_credentials => "#{Rails.root}/config/s3.yml",
:path => ":picture/:id/:style.:extension",
:url => ":s3_domain_url"
validates_attachment_size :data, :less_than => 2.megabytes
validates_attachment_presence :data
def url_content
url(:content)
end
end
And i received the next error:
/home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206:in `const_missing_from_s3_library': uninitialized constant Ckeditor::Asset (NameError)
from /home/jorge/trabajos/blanet/app/models/ckeditor/attachment_file.rb:1:in `<top (required)>'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/engine.rb:138:in `block (2 levels) in eager_load!'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/engine.rb:137:in `each'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/engine.rb:137:in `block in eager_load!'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/engine.rb:135:in `each'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/engine.rb:135:in `eager_load!'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/application.rb:108:in `eager_load!'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/application/finisher.rb:41:in `block in <module:Finisher>'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/initializable.rb:25:in `instance_exec'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/initializable.rb:25:in `run'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/initializable.rb:50:in `block in run_initializers'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/initializable.rb:49:in `each'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/initializable.rb:49:in `run_initializers'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/application.rb:134:in `initialize!'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/application.rb:77:in `method_missing'
from /home/jorge/trabajos/blanet/config/environment.rb:5:in `<top (required)>'
from /home/jorge/trabajos/blanet/config.ru:3:in `block in <main>'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/rack-1.2.3/lib/rack/builder.rb:46:in `instance_eval'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/rack-1.2.3/lib/rack/builder.rb:46:in `initialize'
from /home/jorge/trabajos/blanet/config.ru:1:in `new'
from /home/jorge/trabajos/blanet/config.ru:1:in `<main>'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/rack-1.2.3/lib/rack/builder.rb:35:in `eval'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/rack-1.2.3/lib/rack/builder.rb:35:in `parse_file'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/rack-1.2.3/lib/rack/server.rb:162:in `app'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/rack-1.2.3/lib/rack/server.rb:253:in `wrapped_app'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/rack-1.2.3/lib/rack/server.rb:204:in `start'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/commands/server.rb:65:in `start'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/commands.rb:30:in `block in <top (required)>'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/commands.rb:27:in `tap'
from /home/jorge/.rvm/gems/ruby-1.9.2-p290#rails3/gems/railties-3.0.9/lib/rails/commands.rb:27:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Any one can help me?
Thanks for advance.
It looks like it can't load the parent class for your attachments. Is Ckeditor::Asset defined somewhere? Is it being loaded? Maybe you need a require ckeditor/asset somewhere?

Rails 3.2.5 Sorcery and delayed job integration to send emails

I am developing a Rails 3.2.5 application with Sorcery for authentication and delayed_job for background processing [ sorcery (0.7.12), delayed_job (3.0.3), delayed_job_active_record (0.3.2) ].
My Sorcery configuration looks like this:
Rails.application.config.sorcery.submodules = [:remember_me, :reset_password, :user_activation, :brute_force_protection, :activity_logging, :external]
Rails.application.config.sorcery.configure do |config|
--[clip]
config.user_config do |user|
user.user_activation_mailer = UserMailer
user.activation_success_email_method_name = nil
end
config.user_class = "Account"
module Sorcery
module Model
module InstanceMethods
def generic_send_email(method, mailer)
config = sorcery_config
mail = config.send(mailer).delay.send(config.send(method), self)
end
end
end
end
end
Gemfile
source 'https://rubygems.org'
gem 'rails', '3.2.5'
# gem 'thin' # delayed_job has problems with this
gem 'pg'
gem 'mongrel', '1.2.0.pre2'
gem 'bcrypt-ruby', '~> 3.0.0'
gem 'sorcery'
gem 'simple_form'
gem 'high_voltage' # static pages
gem 'squeel'
gem 'kaminari'
gem 'bourbon'
gem 'rabl'
gem 'yajl-ruby'
gem 'geocoder'
gem "carrierwave"
gem "cloudinary"
gem 'haml'
gem 'rails-settings-cached'
gem 'configatron'
gem 'store_configurable'
gem 'has_serialized'
gem 'rolify'
gem 'cancan'
gem 'delayed_job_active_record'
gem 'simple_postmark'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'bootstrap-sass'
gem 'sass-rails', '~> 3.2.3'
gem 'uglifier', '>= 1.0.3'
gem 'therubyracer'
gem 'execjs'
end
gem 'jquery-rails'
group :development, :test do
gem 'rspec'
gem 'rspec-rails' , ">= 2.5.0"
gem 'rails3-generators'
gem 'hpricot' # needed by devise views generator
gem 'awesome_print'
end
While creating account, a job is added to delayed_jobs table but with a error:
"{Job failed to load: uninitialized constant BCrypt. Handler: "--- !ruby/object:Delayed::PerformableMailer \nargs: \n- :activation_needed_email_method_name\n- !ruby/ActiveRecord:Account \n attributes: \n id: 100\n username: student.ten#retinaindia.org\n email: student.ten#retinaindia.org\n crypted_password: !str:BCrypt::Password \n str: $2a$10$ndL2tnPLheemvBsNqPXMwew6Pakf/Kf8xxt1Q54xkRWS3JfMaTAC6\n :#checksum: w6Pakf/Kf8xxt1Q54xkRWS3JfMaTAC6\n :#cost: 10\n :#salt: $2a$10$ndL2tnPLheemvBsNqPXMwe\n :#version: !str:BCrypt::Password 2a\n salt: Aatzxp2m4fp2CYy9ZoCr\n user_id: 74\n user_type: Student\n created_at: &id001 2012-07-09 08:34:23.981292 Z\n updated_at: *id001\n remember_me_token: \n remember_me_token_expires_at: \n reset_password_token: \n reset_password_token_expires_at: \n reset_password_email_sent_at: \n failed_logins_count: 0\n lock_expires_at: \n unlock_token: \n last_login_at: \n last_logout_at: \n last_activity_at: \n activation_state: pending\n activation_token: 7XAssTaEqsorDWpbpUY9\n activation_token_expires_at: \n created_by: Admin\nmethod_name: :send\nobject: !ruby/class UserMailer\n"
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/backend/base.rb:86:in `rescue in payload_object'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/backend/base.rb:84:in `payload_object'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/backend/base.rb:94:in `block in invoke_job'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:60:in `call'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:60:in `block in initialize'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:65:in `call'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:65:in `execute'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:38:in `run_callbacks'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/backend/base.rb:91:in `invoke_job'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/worker.rb:182:in `block (2 levels) in run'
/home/syed/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/timeout.rb:57:in `timeout'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/worker.rb:182:in `block in run'
/home/syed/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/benchmark.rb:309:in `realtime'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/worker.rb:181:in `run'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/worker.rb:238:in `block in reserve_and_run_one_job'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:60:in `call'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:60:in `block in initialize'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:65:in `call'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:65:in `execute'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:38:in `run_callbacks'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/worker.rb:238:in `reserve_and_run_one_job'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/worker.rb:166:in `block in work_off'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/worker.rb:165:in `times'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/worker.rb:165:in `work_off'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/worker.rb:133:in `block (4 levels) in start'
/home/syed/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/benchmark.rb:309:in `realtime'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/worker.rb:132:in `block (3 levels) in start'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:60:in `call'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:60:in `block in initialize'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:65:in `call'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:65:in `execute'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:38:in `run_callbacks'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/worker.rb:129:in `block (2 levels) in start'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/worker.rb:128:in `loop'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/worker.rb:128:in `block in start'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/plugins/clear_locks.rb:7:in `call'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/plugins/clear_locks.rb:7:in `block (2 levels) in <class:ClearLocks>'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:78:in `call'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:78:in `block (2 levels) in add'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:60:in `call'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:60:in `block in initialize'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:78:in `call'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:78:in `block in add'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:65:in `call'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:65:in `execute'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/lifecycle.rb:38:in `run_callbacks'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/worker.rb:127:in `start'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/command.rb:101:in `run'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/command.rb:89:in `block in run_process'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.0.10/lib/daemons/application.rb:215:in `call'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.0.10/lib/daemons/application.rb:215:in `block in start_proc'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.0.10/lib/daemons/daemonize.rb:192:in `call'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.0.10/lib/daemons/daemonize.rb:192:in `call_as_daemon'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.0.10/lib/daemons/application.rb:219:in `start_proc'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.0.10/lib/daemons/application.rb:255:in `start'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.0.10/lib/daemons/application_group.rb:123:in `block (2 levels) in start_all'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.0.10/lib/daemons/application_group.rb:122:in `fork'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.0.10/lib/daemons/application_group.rb:122:in `block in start_all'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.0.10/lib/daemons/application_group.rb:121:in `each'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.0.10/lib/daemons/application_group.rb:121:in `start_all'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.0.10/lib/daemons/controller.rb:79:in `run'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.0.10/lib/daemons.rb:188:in `block in run_proc'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.0.10/lib/daemons/cmdline.rb:105:in `call'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.0.10/lib/daemons/cmdline.rb:105:in `catch_exceptions'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.0.10/lib/daemons.rb:187:in `run_proc'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/command.rb:87:in `run_process'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/command.rb:80:in `block in daemonize'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/command.rb:78:in `times'
/home/syed/.rvm/gems/ruby-1.9.2-p0/gems/delayed_job-3.0.3/lib/delayed/command.rb:78:in `daemonize'
script/delayed_job:5:in `<main>'"
This is the handler:
"--- !ruby/object:Delayed::PerformableMailer
args:
- :activation_needed_email_method_name
- !ruby/ActiveRecord:Account
attributes:
id: 100
username: student.ten#retinaindia.org
email: student.ten#retinaindia.org
crypted_password: !str:BCrypt::Password
str: $2a$10$ndL2tnPLheemvBsNqPXMwew6Pakf/Kf8xxt1Q54xkRWS3JfMaTAC6
:#checksum: w6Pakf/Kf8xxt1Q54xkRWS3JfMaTAC6
:#cost: 10
:#salt: $2a$10$ndL2tnPLheemvBsNqPXMwe
:#version: !str:BCrypt::Password 2a
salt: Aatzxp2m4fp2CYy9ZoCr
user_id: 74
user_type: Student
created_at: &id001 2012-07-09 08:34:23.981292 Z
updated_at: *id001
remember_me_token:
remember_me_token_expires_at:
reset_password_token:
reset_password_token_expires_at:
reset_password_email_sent_at:
failed_logins_count: 0
lock_expires_at:
unlock_token:
last_login_at:
last_logout_at:
last_activity_at:
activation_state: pending
activation_token: 7XAssTaEqsorDWpbpUY9
activation_token_expires_at:
created_by: Admin
method_name: :send
object: !ruby/class UserMailer
"
[edit]
This error is thrown when it is unable to perform YAML.load. But, weirdly enough when I tried to manually do that in the console, it is loaded with any problems.
ruby-1.9.2-p0 > YAML.load("--- !ruby/object:Delayed::PerformableMailer
ruby-1.9.2-p0"> args:
ruby-1.9.2-p0"> - !ruby/ActiveRecord:Account
ruby-1.9.2-p0"> attributes:
ruby-1.9.2-p0"> id: 106
ruby-1.9.2-p0"> username: student.two#retinaindia.org
ruby-1.9.2-p0"> email: student.two#retinaindia.org
ruby-1.9.2-p0"> crypted_password: !str:BCrypt::Password
ruby-1.9.2-p0"> str: $2a$10$przMrMWjJqTetGj4IhLsEO9AjM12rnTuP2ZiJwz1xzSgr70dvJdM2
ruby-1.9.2-p0"> :#checksum: 9AjM12rnTuP2ZiJwz1xzSgr70dvJdM2
ruby-1.9.2-p0"> :#cost: 10
ruby-1.9.2-p0"> :#salt: $2a$10$przMrMWjJqTetGj4IhLsEO
ruby-1.9.2-p0"> :#version: !str:BCrypt::Password 2a
ruby-1.9.2-p0"> salt: f5CppR8NySi4VEEFNcLT
ruby-1.9.2-p0"> user_id: 81
ruby-1.9.2-p0"> user_type: Student
ruby-1.9.2-p0"> created_at: &id001 2012-07-09 11:08:49.705831 Z
ruby-1.9.2-p0"> updated_at: *id001
ruby-1.9.2-p0"> remember_me_token:
ruby-1.9.2-p0"> remember_me_token_expires_at:
ruby-1.9.2-p0"> reset_password_token:
ruby-1.9.2-p0"> reset_password_token_expires_at:
ruby-1.9.2-p0"> reset_password_email_sent_at:
ruby-1.9.2-p0"> failed_logins_count: 0
ruby-1.9.2-p0"> lock_expires_at:
ruby-1.9.2-p0"> unlock_token:
ruby-1.9.2-p0"> last_login_at:
ruby-1.9.2-p0"> last_logout_at:
ruby-1.9.2-p0"> last_activity_at:
ruby-1.9.2-p0"> activation_state: pending
ruby-1.9.2-p0"> activation_token: YZWfZBoGZj2qC6sVHsbQ
ruby-1.9.2-p0"> activation_token_expires_at:
ruby-1.9.2-p0"> created_by: Self
ruby-1.9.2-p0"> method_name: :activation_needed_email
ruby-1.9.2-p0"> object: !ruby/class Notifier
ruby-1.9.2-p0"> ")
Account Load (2.4ms) SELECT "accounts".* FROM "accounts" WHERE "accounts"."id" = $1 LIMIT 1 [["id", 106]]
=> #<Delayed::PerformableMailer:0x9b39a08 #args=[#<Account id: 106, username: "student.two#retinaindia.org", email: "student.two#retinaindia.org", crypted_password: "$2a$10$przMrMWjJqTetGj4IhLsEO9AjM12rnTuP2ZiJwz1xzSg...", salt: "f5CppR8NySi4VEEFNcLT", user_id: 81, user_type: "Student", created_at: "2012-07-09 11:08:49", updated_at: "2012-07-09 11:08:49", remember_me_token: nil, remember_me_token_expires_at: nil, reset_password_token: nil, reset_password_token_expires_at: nil, reset_password_email_sent_at: nil, failed_logins_count: 0, lock_expires_at: nil, unlock_token: nil, last_login_at: nil, last_logout_at: nil, last_activity_at: nil, activation_state: "pending", activation_token: "YZWfZBoGZj2qC6sVHsbQ", activation_token_expires_at: nil, created_by: "Self">], #method_name=:activation_needed_email, #object=Notifier>
Answering my own question since the following approach works for me now at least.
require 'bcrypt' in delayed_job_config.rb
require "bcrypt"
if defined?(BCrypt)
puts "BCrypt defined."
else
puts "BCrypt failed loaded!!"
end
Delayed::Worker.destroy_failed_jobs = false
2. Still can't get user_activation module of Sorcery to work and send emails automatillay through delayed_job. Had to disable that module altogether and send activation mails manually.

mysql2 rails3.1 error

I am on windows xp, with rails 3.1
and i use mysql2 0.2.6
but when i
when i try to make a request like:
Product.all
i got this responce:
irb(main):001:0> Product.all
←[1m←[36m (0.0ms)←[0m ←[1mSHOW TABLES←[0m
←[1m←[35m (0.0ms)←[0m describe `products`
ArgumentError: wrong number of arguments (3 for 2)
from D:/projects/rails/_API/rake/ruby/1.9.1/gems/mysql2-0.2.6-x86-mingw32/lib/active_record/connection_adapters/mysql2_adapter.rb:634:in `select'
from D:/projects/rails/_API/rake/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/database_statements.rb:18:in `select_all'
from D:/projects/rails/_API/rake/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/query_cache.rb:63:in `select_all'
from D:/projects/rails/_API/rake/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/base.rb:470:in `find_by_sql'
from D:/projects/rails/_API/rake/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/relation.rb:111:in `to_a'
from D:/projects/rails/_API/rake/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/relation/finder_methods.rb:155:in `all'
from D:in `all'
from (irb):1
from D:/projects/rails/_API/rake/ruby/1.9.1/gems/railties-3.1.0/lib/rails/commands/console.rb:45:in `start'
from D:/projects/rails/_API/rake/ruby/1.9.1/gems/railties-3.1.0/lib/rails/commands/console.rb:8:in `start'
from D:/projects/rails/_API/rake/ruby/1.9.1/gems/railties-3.1.0/lib/rails/commands.rb:40:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
my controller:
def index
#products = Product.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: #products }
end
end
my models :
class Product < ActiveRecord::Base
define_index do
indexes brand
indexes name
indexes denomination
end
end
mysql2 0.2.6 isn't compatible with Rails 3.1.
You should either downgrade Rails to 3.0.7 or upgrade mysql2 to 0.3.1.

Getting an error with custom validation in a Rails 3 ActiveModel

I'm trying to use the Date Validator Gem but I am running into an error and I'm not sure if it's because the model isn't Active Record or not (I've seen people suggest that validation is a bit funky in ActiveModel when not in ActiveRecord).
I am using Ruby 1.9.2 & Rails 3.0.7. I've attached both the class and the error below.
Thanks in advance for any help!
Class
require 'ice_cube'
require 'active_support'
require 'active_support/time_with_zone'
require 'ostruct'
require 'tzinfo'
require 'active_model'
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming
class Schedule
attr_accessor :yaml, :repeat, :interval, :interval_unit, :start_time, :start_date, :end_date, :end_time, :ends, :on, :after, :monday, :tuesday, :wednesday, :thursday, :friday, :saturday, :sunday
validates_presence_of :repeat, :start_date, :start_time, :end_date, :end_time, :ends
validates_presence_of :interval, :interval_unit, :if => :ends_never?
validates_presence_of :on, :if => :ends_on_date?
validates_numericality_of :after, :greater_than => 0, :if => :ends_after_recurrences?
validates :start_date, :date => { :after => Time.now }
validates :end_date, :date => { :after => :start_date }
validates :on, :date => { :after => :end_date }
def initialize(attributes = {})
end
def persisted?
false
end
private
def parse_schedule
if :repeat == 0
get_repeatable
end
end
def parse_yaml
end
def ends_on_date?
return :ends == "on"
end
def ends_never?
return :ends == "never"
end
def ends_after_recurrences?
return :ends == "after"
end
end
Error from Rails Console
ruby-1.9.2-p180 :001 > s = Schedule.new
NoMethodError: undefined method `new' for DateValidator:Module
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/activemodel-3.0.7/lib/active_model/validations/with.rb:70:in `block in validates_with'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/activemodel-3.0.7/lib/active_model/validations/with.rb:69:in `each'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/activemodel-3.0.7/lib/active_model/validations/with.rb:69:in `validates_with'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/activemodel-3.0.7/lib/active_model/validations/validates.rb:90:in `block in validates'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/activemodel-3.0.7/lib/active_model/validations/validates.rb:83:in `each'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/activemodel-3.0.7/lib/active_model/validations/validates.rb:83:in `validates'
from /Users/chance/Sites/EatingNow/app/models/schedule.rb:16:in `<class:Schedule>'
from /Users/chance/Sites/EatingNow/app/models/schedule.rb:10:in `<top (required)>'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:454:in `load'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:454:in `block in load_file'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:596:in `new_constants_in'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:453:in `load_file'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:340:in `require_or_load'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:491:in `load_missing_constant'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:183:in `block in const_missing'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:181:in `each'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:181:in `const_missing'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/rspec/core/backward_compatibility.rb:20:in `const_missing'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/rspec-expectations-2.5.0/lib/rspec/expectations/backward_compatibility.rb:6:in `const_missing'
from (irb):1
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/commands/console.rb:44:in `start'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/commands/console.rb:8:in `start'
from /Users/chance/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/commands.rb:23:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
You have included/extended the top-level namespace. Make sure the includes/extends are IN the class.
class Schedule
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming