If the user doesn’t sign up with twitter or facebook the provider attribute is blank and the user is a pro user. I’ve added the pro attribute to the database as a boolean and the default is false.
I’m trying to toggle the pro attribute in the database to true using the code below.
def pro?
toggle!(:pro) if provider.blank?
end
However I get this error.
stack level too deep
I also tried
def pro?
:pro => true if provider.blank?
end
but get this error:
syntax error, unexpected tASSOC, expecting keyword_end
Note I also need to use the pro method because it is used in many other places in the code.
If you have the
proattribute defined as boolean, the following methods are all available for free:pro?: returns the boolean value of theproattributepro=: sets the value ofproA ruby method ending in a
?is expected to return a boolean, without any side-effects.What I would do, in your case, is add a callback:
This will make sure that everytime something is changed in your
user, before saving, it will set thepro-status correctly depending on the provider.Hope this helps.