MongoMapper, Rails, Increment Works in Console but not Controller

Posted by Michael Waxman on Stack Overflow See other posts from Stack Overflow or by Michael Waxman
Published on 2010-06-15T00:00:44Z Indexed on 2010/06/15 0:22 UTC
Read the original article Hit count: 523

I'm using mongo_mapper 0.7.5 and rails 2.3.8, and I have an instance method that works in my console, but not in the controller of my actual app. I have no idea why this is.

#controller
if @friendship.save
   user1.add_friend(user2)
...

#model
...
key :friends_count, Integer, :default => 0
key :followers_count, Integer, :default => 0

def add_friend(user)
   ...
   self.increment(:friends_count => 1)
   user.increment(:followers_count => 1)
   true
end

And this works in the console, but in the controller it does not change the follower count, only the friends count. What gives? The only thing I can even think of is that the way that I'm passing the user in is the problem, but I'm not sure how to fix it.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby