views:

231

answers:

2

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
+3  A: 

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.

Ryan Bigg
A: 

Try this gem

http://rubygems.org/gems/wizardly_gt

I have only just begin playing with wizardly, but the above at least seems to be compatible with Rails 3.

Sanjay
I've used wizardly_gt and emailed Gavin. It doesn't work with Rails 3.
Paul Schreiber