【发布时间】:2013-03-14 13:51:53
【问题描述】:
我的项目中有一个模块位于 lib/.它的内容是这样的:
module Search
module Score
def get_score
return 'something'
end
end
end
此搜索有许多不同的模块,我需要使用 Score。我意识到我需要在我的模型中添加 require (我正在尝试从模型中使用它)。所以这是我的代码(模型):
require 'search'
class User < ActiveRecord::Base
def get_user_score
#tried this :
p Search::Score.get_score #error
#this as well
score_instance = Score.new #error
score = Search::Score.get_score # error undefined method `get_score'
end
end
那么如何重用我在其他类(模块)中的代码?
【问题讨论】:
标签: ruby-on-rails ruby