加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 将Ruby变量值设置为true

发布时间:2020-12-17 01:37:03 所属栏目:百科 来源:网络整理
导读:我是 Ruby / Ruby on Rails的新手.我编写了下面的代码来从api获取一个布尔值. API调用失败,它进入了救援块.但由于某种原因,它将值设置为true.我不明白这是怎么回事. @is_attached = OnDeck.api.check_is_attached(@decision.application_number,current_user
我是 Ruby / Ruby on Rails的新手.我编写了下面的代码来从api获取一个布尔值. API调用失败,它进入了救援块.但由于某种原因,它将值设置为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

解决方法

rails logger在成功记录时返回true:

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

因为这是方法中执行的最后一行,所以当ruby具有隐式返回时返回该值.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读