What's the Rails 3 replacement for ActiveRecord::Errors?
In Rails 2.3.8, this is an object:
>> ActiveRecord::Errors
=> ActiveRecord::Errors
In Rails 3.0.0rc, you get a NameError:
>> ActiveRecord::Errors
NameError: uninitialized constant ActiveRecord::Errors
from (irb):2
I'm trying to make the wizardly generator work with Rails 3.
$ rails g wizardly_scaffold home
But it fails:
/Library/Ruby/Gems/1.8/gems/wizardly_gt-0.1.8.9/lib/validation_group.rb:150:
uninitialized constant ActiveRecord::Errors (NameError)
The line it refers to is this:
ActiveRecord::Errors.send :include, ValidationGroup::ActiveRecord::Errors
Earlier in the file, we see:
module ValidationGroup
module ActiveRecord
...
module Errors # included in ActiveRecord::Errors
def add_with_validation_group(attribute, msg = I18n.translate('activerecord.errors.messages')[:invalid], *args, &block)
add_error = @base.respond_to?(:should_validate?) ? (@base.should_validate?(attribute.to_sym) || attribute == :base) : true
add_without_validation_group(attribute, msg, *args, &block) if add_error
end
...
end
That'd be ActiveModel::Errors
. Things such as validations and error handling have been moved over to Active Model to provide a common API for all ORM Railties such as Active Record, Data Mapper, Mongoid etc. to hook into Rails with.
It would appear the wizardly plugin needs to check for ActiveModel first and if it exists, then include the error handling there rather than ActiveRecord::Errors
. A trivial change.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With