1

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!!

2
  • So what's the problem (more specifically than 'it isn't working')? Is it that the user just isn't seeing "HOORAY", you're getting an exception somewhere, or something else? Commented Aug 21, 2009 at 22:11
  • Chris, the hooray isn't displaying (there's a function to display in view) and if @leveled_up==true self.statpoints+=5 hp=max_hp end isn't running... (never) Commented Aug 21, 2009 at 22:19

1 Answer 1

4

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.