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

2026-04-10 07:281阅读0评论SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

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

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

我是Ruby和Ruby on Rails的新手。我编写了下面的代码来从API获取一个布尔值。API调用失败时,它会进入一个错误处理块。但由于某种原因,它将值设置为true。我不清楚这是如何发生的。代码如下: `@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具有隐式返回时返回该值.

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

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

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

我是Ruby和Ruby on Rails的新手。我编写了下面的代码来从API获取一个布尔值。API调用失败时,它会进入一个错误处理块。但由于某种原因,它将值设置为true。我不清楚这是如何发生的。代码如下: `@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具有隐式返回时返回该值.

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