{"issue":{"created_at":"2011-11-30T02:13:44Z","state":"open","updated_at":"2011-11-30T07:13:31Z","comments":1,"user":{"gravatar_id":"31e2b397e15442a2d3ba42db7bd4584e","id":31725,"url":"https://api.github.com/users/chip","avatar_url":"https://secure.gravatar.com/avatar/31e2b397e15442a2d3ba42db7bd4584e?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","login":"chip"},"body":"Hi,\r\n\r\nGreat work on your gem.  Your docs referenced that it supports ActiveModel, but I didn't see any examples provided on how to do this.  Here I have a simple ActiveModel class:\r\n\r\n```\r\n\r\nrequire 'active_model'\r\n\r\nclass ProductSearch\r\n  include ActiveModel::Validations\r\n\r\n  validates_length_of :keyword, :minimum => 1, \\\r\n                      :message => \"must be at least 1 character.\"\r\n  attr_accessor :keyword\r\n  auto_strip_attributes :keyword\r\n\r\n  def results\r\n    puts \"results keyword=#{@keyword}\"\r\n    @results ||= Solr.search(@keyword)\r\n  end\r\nend\r\n```\r\n\r\nHere's what I put in my Gemfile:\r\n```\r\ngem \"auto_strip_attributes\", \"~> 2.0.2\"\r\n```\r\n\r\nBut when I fire up the Rails console, I get this:\r\n```\r\nruby-1.8.7-p352 :003 > p = ProductSearch.new\r\nNoMethodError: undefined method `auto_strip_attributes' for ProductSearch:Class\r\n\tfrom /Users/chip/code/rentwb/app/models/products/product_search.rb:17\r\n\tfrom /Users/chip/code/rentwb/vendor/bundle/ruby/1.8/gems/activesupport-3.0.10/lib/active_support/dependencies.rb:454:in `load'\r\n\tfrom /Users/chip/code/rentwb/vendor/bundle/ruby/1.8/gems/activesupport-3.0.10/lib/active_support/dependencies.rb:454:in `load_file'\r\n\tfrom /Users/chip/code/rentwb/vendor/bundle/ruby/1.8/gems/activesupport-3.0.10/lib/active_support/dependencies.rb:593:in `new_constants_in'\r\n\tfrom /Users/chip/code/rentwb/vendor/bundle/ruby/1.8/gems/activesupport-3.0.10/lib/active_support/dependencies.rb:453:in `load_file'\r\n\tfrom /Users/chip/code/rentwb/vendor/bundle/ruby/1.8/gems/activesupport-3.0.10/lib/active_support/dependencies.rb:340:in `require_or_load'\r\n\tfrom /Users/chip/code/rentwb/vendor/bundle/ruby/1.8/gems/activesupport-3.0.10/lib/active_support/dependencies.rb:487:in `load_missing_constant'\r\n\tfrom /Users/chip/code/rentwb/vendor/bundle/ruby/1.8/gems/activesupport-3.0.10/lib/active_support/dependencies.rb:183:in `const_missing'\r\n\tfrom /Users/chip/code/rentwb/vendor/bundle/ruby/1.8/gems/activesupport-3.0.10/lib/active_support/dependencies.rb:181:in `each'\r\n\tfrom /Users/chip/code/rentwb/vendor/bundle/ruby/1.8/gems/activesupport-3.0.10/lib/active_support/dependencies.rb:181:in `const_missing'\r\n\tfrom (irb):3\r\n```\r\n\r\nI've verified that this gem is installed here:\r\n```\r\nvendor/bundle/ruby/1.8/gems/auto_strip_attributes-1.1/lib/auto_strip_attributes.rb\r\n```\r\n\r\nWould you be able to provide an example of how to get this to work with ActiveModel?   If I figure this out, I'll submit a Pull Request with an example.  Thanks for your help!\r\n\r\nChip","assignee":null,"id":2396485,"number":2,"pull_request":{"patch_url":null,"html_url":null,"diff_url":null},"labels":[],"title":"Is there ActiveModel support?","closed_at":null,"html_url":"https://github.com/holli/auto_strip_attributes/issues/2","url":"https://api.github.com/repos/holli/auto_strip_attributes/issues/2","milestone":null},"action":"created","comment":{"created_at":"2011-11-30T07:13:31Z","updated_at":"2011-11-30T07:13:31Z","user":{"gravatar_id":"8e2b19390e10338e725eded7c798c8a7","id":100112,"url":"https://api.github.com/users/holli","avatar_url":"https://secure.gravatar.com/avatar/8e2b19390e10338e725eded7c798c8a7?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","login":"holli"},"body":"Hi,\r\n\r\noh. Sorry. Damn. ActiveModel support was removed at some point. It could probably be easily implemented again.\r\n\r\nCurrently the method is only included in ActiveRecord\r\nhttps://github.com/holli/auto_strip_attributes/blob/master/lib/auto_strip_attributes.rb#L77 =>\r\n     ActiveRecord::Base.send(:extend, AutoStripAttributes) if defined? ActiveRecord\r\n\r\nI cant remember why it wasn't included in ActiveModel also. It might be because the way of fetching current values by\r\n     value = record[attribute]\r\n\r\nI'm not sure if ActiveModel supported the same way of using array accessors. So it might need another way for activemodels e.g.\r\n     value = record.is_a?(ActiveRecord) ? record[attribute] : record.send(attribute) \r\n\r\nhttps://github.com/holli/auto_strip_attributes/blob/master/lib/auto_strip_attributes.rb#L13\r\nand same for setter.\r\n\r\nSo yeah, no support for ActiveModels currently. If you fix it somehow and tests pass, make sure to do a Pull request :)\r\n\r\ncheers, Olli\r\n","id":2955995,"url":"https://api.github.com/repos/holli/auto_strip_attributes/issues/comments/2955995"}}