Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Make it work to use normalize_attribute with virtual attributes created with attr_accessor #18

Open
TylerRick opened this Issue · 2 comments

3 participants

@TylerRick

I tried to do this:

class User < ActiveRecord::Base
  attr_accessor :division_id
  normalize_attributes :division_id, :with => [:strip, :blank]
end

But got this error

NoMethodError (super: no superclass method `division_id=' for #<User:0x00000013035300>):

The error comes from the call to super here (attribute_normalizer/model_inclusions.rb):

        define_method "#{attribute}=" do |value|
          super(self.send(:"normalize_#{attribute}", value))
        end

This was my workaround:

module DivisionId
  attr_writer :division_id
end
class User < ActiveRecord::Base
  include DivisionId
  normalize_attributes :division_id, :with => [:strip, :blank]
end  

It would be nice if it just worked without any workaround though. Do you think that would be possible?

The only way I can think of right now to make it just work is to somehow fall back to an alias_method_chain if you can't use super .

@mdeering
Owner

Seems like a reasonable request. Can you tell me what version of the gem you got this error with? I'm pretty sure that we removed the super dependencies. Can you confirm the same error with 1.0.0.rc4?

@mauriciopasquier

I know this issue is really old, but just in case: virtual attributes work just fine with 1.1.X and 1.2.0.b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.