I have a model inheriting directly from ActiveResource::Base
, and I'm trying to run alias_method
for most of the columns in the record's table, but the result is a NameError:
NameError: undefined method
address_line_1' for class
LeadImport::Base'
Yet I can access the attribute:
LeadImport::Base.new.address_line_1 #=> nil (not error)
My class has a table column named address_line_1
, so I fail to see the problem.
class LeadImport::Base < ActiveRecord::Base
alias_method :address_1, :address_line_1
end
specs: Ruby 1.8.7, Rails 2.3.8
According a site I found, you're supposed to use alias_attribute instead:
The problem is that ActiveRecord doesn't create the accessor methods on the fly until the database connection is live and it has parsed the table schema. That's a long time after the class has been loaded.
class LeadImport::Base < ActiveRecord::Base
alias_attribute :address_1, :address_line_1
end
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