如何使用Ruby on Rails将变量值设为true?

更新于
2026-10-03 21:12:28
1阅读来源:SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计211个文字,预计阅读时间需要1分钟。

我是Ruby和Ruby on Rails的新手。我编写了以下代码从API获取一个布尔值。API调用失败,它进入了救援块。但不知何故,它将值设置为true。我不明白这是怎么回传的。

ruby@is_attached=OnDeck.api.che

我是 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具有隐式返回时返回该值.

本文共计211个文字,预计阅读时间需要1分钟。

我是Ruby和Ruby on Rails的新手。我编写了以下代码从API获取一个布尔值。API调用失败,它进入了救援块。但不知何故,它将值设置为true。我不明白这是怎么回传的。

ruby@is_attached=OnDeck.api.che

我是 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具有隐式返回时返回该值.