views:

341

answers:

1

Hello.

In my controller, I have this:

user.save
if user.leveled_up==true
    flash[:notice]="HOOOORAY!!!"
end

and in my model I have:

before_save :check_xp

# ....

def leveled_up=(leveled_up)
     @leveled_up=leveled_up
     if @leveled_up==true
      self.statpoints+=5 
      hp=max_hp
     end
    end

    def leveled_up
     @leveled_up
    end

    private 
    def check_xp
     leveled_up=false
     case self.xp
     when 0..999
      self.level=1
     when 1000..2999
      leveled_up=true if self.level==1
      self.level=2
     when 3000..4999
      leveled_up=true if self.level==2
      self.level=3
     when 5000..9999
      leveled_up=true if self.level==3
      self.level=4

# ...

     end

    end

But this isn't working. Even if the User leveled up the function leveled_up returns false...

I must be doing something wrong...

Thanks!!

+1  A: 

here leveled_up=false is not a method call. You actually created a local variable called leveled_up, it has nothing to do with the method. to call the method, use

self.leveled_up
ez
Thanks! That fixed it...
Gabriel Bianconi