gem install rubyoverflow
irb
> require 'rubyoverflow'
=> true
可是:
require 'rubyoverflow'
include Rubyoverflow
class QuestionsController < ApplicationController
def question_by_tag
ruby_q = Questions.retrieve_by_tag('ruby')
获取错误:
LoadError in QuestionsController#question_by_tag no 加载这样的文件 - rubyoverflow
Rails.root: d:/伪影的/ dev /项目/堆
应用程序/控制器/ questions_controller.rb:1:在 `'
加载时发生此错误 以下文件:rubyoverflow
是否有任何特殊规则要在控制器中导入模块?
答案 0 :(得分:2)
为什么同时使用require
和include
? include Rubyoverflow
就足够了
<强> UPD 强>
对于gem,您应该将其添加到Gemfile
(Rails 3.x)或config/environment.rb
(Rails 2.x)
# Gemfile
gem "rubyoverflow"
# environment.rb
config.gem "rubyoverflow"
然后为Rails 3.x运行bundle
,为Rails 2.x运行rake gems:install