Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

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

TylerRick opened this Issue Sep 13, 2011 · 2 comments


None yet
3 participants

I tried to do this:

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

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))

This was my workaround:

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

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 commented Sep 14, 2011

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 commented Jul 8, 2014

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

@mdeering mdeering closed this Aug 15, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment