Jeremy Lynch
Jeremy Lynch

Reputation: 7230

if boolean == false syntax error

I can't get the following syntax to work:

if document.anonymous == false ?

I get this error: " syntax error, unexpected tIDENTIFIER, expecting keyword_do or '{' or '(' "

Here is the corresponding field for "anonymous" in the document model

field :anonymous, type: Boolean, default: true

Thank you in advance!

Upvotes: 1

Views: 8133

Answers (4)

Jarvis Johnson
Jarvis Johnson

Reputation: 464

Anyone looking at this now, for booleans you can simply use:

document.anonymous? - returns true for boolean with value 1

!document.anonymous? - returns true for boolean with value 0

Upvotes: 0

Salil
Salil

Reputation: 47532

either use

if document.anonymous == false #OR unless document.anonymous

else

end

OR

document.anonymous == false ? () : ()

Note:- In Ruby only false and nil are falsey. Ref this

Upvotes: 1

Billy Chan
Billy Chan

Reputation: 24815

There should not be question mark. Use this

if document.anonymous == false

Upvotes: 1

Bachan Smruty
Bachan Smruty

Reputation: 5734

Try unless document.anonymous in stead of if document.anonymous == false ?

Upvotes: 3

Related Questions