Fixnum的未定义方法`之间'

时间:2014-09-28 16:18:41

标签: ruby-on-rails ruby

我有一个网址:

xxxx/xxx?status=2

我从网址获取了:status参数的值,将其转换为整数,并尝试在其上使用between方法:

params[:status].to_i.between.(0, 3)

但是我收到如下错误:

undefined method `between' for 1:Fixnum

我检查了班级祖先:

params[:status].to_i.class.ancestors
# => [Fixnum, JSON::Ext::Generator::GeneratorMethods::Fixnum, Integer, Numeric, Comparable, Object, ActiveSupport::Dependencies::Loadable, JSON::Ext::Generator::GeneratorMethods::Object, Kernel, BasicObject]

我可以看到Comparable,所以我不知道为什么我不能这样做。

1 个答案:

答案 0 :(得分:4)

方法名称有误:不是between,而是between?

params[:status].to_i.between?(0, 3)

检查Ruby Doc

相关问题