未定义的方法“空白?"对于“123":字符串(NoMethodError) [英] undefined method `blank?' for "123":String (NoMethodError)

查看:56
本文介绍了未定义的方法“空白?"对于“123":字符串(NoMethodError)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在检查 ruby​​ 中的类变量时遇到这个奇怪的错误

I am getting this strange error for a when I am checking a class variable in ruby

未定义的方法空白?"对于 "123":String (NoMethodError)

undefined method `blank?' for "123":String (NoMethodError)

我所做的只是Employee.set_id.blank?

知道为什么会发生这种情况吗?

Any ideas why this could be happening?

谢谢.

推荐答案

blank? 方法是为 Object 类的后代的每个 Ruby 对象定义的<代码>activesupport gem (https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/object/blank.rb).

The blank? method is defined for every Ruby object that is descendant of the Object class in activesupport gem (https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/object/blank.rb).

这个 gem 是 Rails 框架的一部分.但是,如果您仍然想在您的非 Rails Ruby 项目中使用 activesupport 的这个实用程序,您可以在源文件中使用以下语句要求它:

This gem is part of Rails framework. However, if you still want to use this utility of activesupport in your non-Rails Ruby project, you can require it in your source files with the sentence:

require 'active_support/core_ext'

确保你已经在你的系统中安装了 activesupport gem.

Make sure you have installed activesupport gem in your system.

这篇关于未定义的方法“空白?"对于“123":字符串(NoMethodError)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆