2017-10-06 86 views
3

我是Ruby/Ruby on Rails的新手。我写了下面的代码从api获取布尔值。 API调用失败,并且它去救援块。但由于某种原因,它将该值设置为true。我不明白这是怎么发生的。Ruby变量值设置为true

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

API调用/客户包装代码

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 

回答

6

轨道记录器上成功登录返回true

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

因为这是在该方法中执行的最后一行时,该值是返回红宝石有隐含的回报。

+2

正确的,你仍然可以返回不管你从急救块的愿望。 – whodini9

+0

哦,谢谢!应该想到这一点。 – NewQueries

1
Rails.logger.error(string) 

返回true,可以看出:

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