NewQueries
NewQueries

Reputation: 4941

Ruby variable value set to true

I am new to Ruby/ Ruby on Rails. I wrote the below code to get a boolean value from api. The API call failed and it went to the rescue block. But for some reason, it set the value to true. I don't understand how that happened.

@is_attached = OnDeck.api.check_is_attached(@decision.application_number, current_user)

Api call / client wrapper Code

def check_is_attached(app_number, user)
   begin
        client.check_is_attached(app_number, user.auth_token)
   rescue OnDeckException::MerchantApiException => e
        Rails.logger.error("Caught exception #{e} while calling check_mbs_attached for app_number : #{app_number}")
 end
end

Upvotes: 3

Views: 163

Answers (2)

ulferts
ulferts

Reputation: 2242

The rails logger returns true on successfully logging:

[2] pry(main)> Rails.logger.error("Caught exception")
Caught exception
=> true

Because that is the last line executed in the method, that value is returned as ruby has implicit return.

Upvotes: 6

jvillian
jvillian

Reputation: 20253

Rails.logger.error(string)

returns true as can be seen:

2.3.1 :002 > Rails.logger.error('foo')
foo
 => true 

Upvotes: 1

Related Questions