Question: I am getting a request from mobile app. They are sending a variable `isbookmarked` that can be either `1` or `0`. I am checking in if statement. 

```
if isbookmarked
  do something
else
  do something
end

```

The `else` part is never executed because `0` is not recognised as `false` 

How can I achieve this?

Answer: 
In Ruby everything is truthy except for `nil` and `false`. Thus both `0` and `1` are truthy - you will never reach the `else` part with this set up.

So in your case you want to check exactly for `0` or `1`:

```
if isbookmarked == 1
  do something
elsif isbookmarked == 0
  do something
end

```
I would argue that you should use the same logic that Rails uses to identify booleans. Rails implements [type casting to booleans](https://github.com/rails/rails/blob/master/activemodel/lib/active_model/type/boolean.rb) like this:

```
FALSE_VALUES = [false, 0, "0", "f", "F", "false", "FALSE", "off", "OFF"].to_set

def cast_value(value)
  if value == ""
    nil
  else
    !FALSE_VALUES.include?(value)
  end
end

```

You can use this implementation like this (Rails 5 version):

```
ActiveModel::Type::Boolean.new.cast(isbookmarked)

```

Or the Rails 4.2 versions would look like this:

```
ActiveRecord::Type::Boolean.new.type_cast_from_user(isbookmarked)

```