airblade/paper_trail — Issue #135: Deprecation warning for writing arbitrary attributes
Author: jasonnoble
Created: 2012-03-08 21:14:54+00:00
State: open

When we run the test suite, we're getting the following deprecation warning:

DEPRECATION WARNING: You're trying to create an attribute `sacrificial_column'. Writing arbitrary attributes on a model is deprecated. Please just use `attr_writer` etc. (called from block (2 levels) in reify at /Users/jasonn/workspace/paper_trail/lib/paper_trail/version.rb:70)

This could be fixed by modifying version.rb:

attrs.each do |k, v|
begin
ActiveSupport::Deprecation.silence do
model.send :write_attribute, k.to_sym , v
end
rescue NoMethodError
logger.warn "Attribute #{k} does not exist on #{item_type} (Version id: #{id})."
end
end

However this could make it break with a later version of Rails.

Perhaps a better fix would be to verify the model responds to the attribute= method before calling write_attribute?