Reputation: 42049
I'm playing around with the Ruby Twitter gem, which, for example, allows you to check if a Twitter user's account is locked. The user's account I am testing is locked.
If I do
@awish = Twitter.user("twitteruser").protected?
and then in a view do
<%= @awish %>
it says "true"
However. when I try to write a method to test this and assign the response to a variable depending on whether it's locked or not, it's telling me that it's "not locked", when I would be expecting it to say it's "locked". So I think I've screwed up this if/else statement somehow (note, I'm a bit of a noob)
Can you explain what I've done wrong?
def awisprotect
@awish = Twitter.user("twitteruser").protected?
if @awish == "true"
@answer = "locked"
else
@answer = "not locked"
end
render :js => "$('div.awishanswer').html(' #{ @answer } ');"
end
Upvotes: 0
Views: 42
Reputation: 16844
the protected?
method should either return true
or false
.
(rather than "true"
or "false"
)
So your method can be much simpler. (you also don't need an instance variable)
def awisprotect
if Twitter.user("twitteruser").protected?
answer = "locked"
else
answer = "not locked"
end
render :js => "$('div.awishanswer').html(' #{ answer } ');"
end
Upvotes: 2