Browse files

Stop clobbering ActiveModel's accessible_attributes method

This works around an incompatibility with Rails 3.2.4+ in which accessible attributes are role-specific (see the ParamsWrapper metal) and need to accept a role argument.

This fix doesn't go all the way down the road of respecting role-specific accessible attributes but silently ignores the passed-in role.
  • Loading branch information...
1 parent 28d005e commit 4d35c6704a9b6b259a85b339f9ecaf9ca6966602 @laserlemon laserlemon committed Jun 1, 2012
Showing with 18 additions and 2 deletions.
  1. +18 −2 lib/mongo_mapper/plugins/accessible.rb
@@ -4,13 +4,21 @@ module Accessible
extend ActiveSupport::Concern
included do
- class_attribute :accessible_attributes
+ class_attribute :_accessible_attributes
module ClassMethods
def attr_accessible(*attrs)
raise if try(:protected_attributes?)
- self.accessible_attributes = + (accessible_attributes || [])
+ self._accessible_attributes = + (_accessible_attributes || [])
+ end
+ def accessible_attributes(*)
+ _accessible_attributes
+ end
+ def accessible_attributes?
+ _accessible_attributes?
@@ -26,6 +34,14 @@ def update_attributes!(attrs={})
+ def accessible_attributes(*args)
+ self.class.accessible_attributes(*args)
+ end
+ def accessible_attributes?
+ self.class.accessible_attributes?
+ end
def filter_inaccessible_attrs(attrs)
return attrs if !accessible_attributes? || attrs.blank?

14 comments on commit 4d35c67


ryana replied Jun 14, 2012

I would adore a patch gem release for this :)

Yes please.

Anything keeping this from being released as a gem update? Even though @laserlemon figured it out, and he's on my team. I still lost an hour trying to upgrade an app to rails v3.2.6 before I remembered this might be the problem.

For me, the error was extremely obscure messing with Rails' dependency loading of some controllers but not others.

marks replied Jul 7, 2012

Until a new gemfile is released, what is the workaround? I added gem "mongo_mapper", :git => "" to my gemfile but still get the following:

1.9.3p194 :003 > Geo.all
ArgumentError: wrong number of arguments (0 for 1)
    from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/mongo_mapper-0.11.1/lib/mongo_mapper/plugins/modifiers.rb:127:in `pop'
    from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/activemodel-3.2.6/lib/active_model/dirty.rb:154:in `attribute_will_change!'
    from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/mongo_mapper-0.11.1/lib/mongo_mapper/plugins/dirty.rb:49:in `write_key'````

@marks -- FWIW, I forked the repository, then referenced my fork from bundler and the problem cleared up. Your environment looks very similar to mine (, and I don't see any new commits in the main-repo, so I'd expect yours to have cleared up too.

@marks We did this and it fixed our problems with rails v3.2.4+

gem "mongo_mapper", github: "jnunemaker/mongomapper" # pretty much same as you

marks replied Jul 9, 2012

@levicook and @zmoazeni thanks for following up. I actually think this was a different issue now. It seems like my issue was that the data I ingested has a field named pop which angered the Ruby/ActiveModel/Mongo gods. I'll try going back to the latest gem version later to see if it was indeed unrelated to all this.

Sorry and thanks again!


jnunemaker replied Jul 9, 2012

Yo. So what do I need to do? I have been swamped and not following along. @laserlemon you need release gem capabilities?


laserlemon replied Jul 9, 2012

@jnunemaker Yes, please!

Any update on a patch release?


jnunemaker replied Jul 21, 2012

Done. Miscommunication. I think I was suppose to tell Steve when I was done with TravisCI stuff and I didn't. Just pushed out 0.11.2.

Please sign in to comment.