【发布时间】:2014-08-09 14:32:30
【问题描述】:
在我的应用程序中,我想添加一个名为 Prototyp 的辅助类:
class Prototyp
def initialize
......
@fields = JSON.parse('{' + arr.join(',') + '}')
end
def correct(word)
@fields.each do |key, array|
word.gsub! "\\" + key , [array.hex].pack("U")
end
return word
end
end
我先把它添加到文件夹lib到lib\Prototyp.rb
然后我尝试在模型类中调用它:
class Person < ActiveRecord::Base
def self.create(file)
pro = Prototyp.new
...
但不知何故我得到了这个错误:
NameError: uninitialized constant Person::Prototyp
C:/Sites/blazing/app/models/person.rb:3:in `create'
我做错了什么?我该如何解决这个问题?谢谢
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-4