Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

ruby

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

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

all I am doing is Employee.set_id.blank?

Any ideas why this could be happening?

Thanks.

like image 465
opensource-developer Avatar asked Jun 16 '16 05:06

opensource-developer


2 Answers

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).

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'

Make sure you have installed activesupport gem in your system.

like image 190
Daniel Ruiz Avatar answered Oct 29 '22 11:10

Daniel Ruiz


Use Employee.set_id.nil? || Employee.set_id.strip.empty? instead.

String#blank? is defined in ActiveSupport

like image 31
scorix Avatar answered Oct 29 '22 13:10

scorix