2013-09-27 67 views
1

我正在尝试使用我刚才在Rails项目中写过的一个愚蠢的小机架宝石,但是我每次调用它时都会收到uninitialized constant错误。这让我疯狂,因为我之前有already written Rack gems,而那些在我的Rails项目中工作得很好。在Rails中使用Rack Gem

在我的Gemfile:

gem 'hide_heroku', :git => 'https://github.com/ykessler/hide-heroku' 

在我的application.rb中:

module Tester 
    class Application < Rails::Application 

    config.middleware.use Rack::HideHeroku 

但是从我的本地服务器,我得到:

未初始化的常量架:: HideHeroku(NameError)

宝石:

module Rack 

    class HideHeroku 

    def initialize(app) 
     @app=app 
    end 

    def call(env) 
     @status, @headers, @response = @app.call(env) 
     @request = Rack::Request.new(env) 
     [@status, _apply_headers, @response] 
    end 

    private 

     def _apply_headers 
     if /\.herokuapp\.com\/?.*/ =~ @request.url 
      @headers['X-Robots-Tag'] = 'noindex, nofollow' 
     end 
     @headers 
     end 

    end 

end 

见这里:https://github.com/ykessler/hide-heroku

回答

2

这里的问题可能是该项目的结构。你需要有一个lib/hide_heroku.rb文件在您的宝石,它引导了宝石,或者你需要指定你的宝石线的需要路径,像这样:

gem 'hide_heroku', :git => 'https://github.com/ykessler/hide-heroku', :require => "rack/hide_heroku" 

(或者你可以require 'rack/hide_heroku'在你的应用程序)。

当您拨打Bundler.setup时Bundler会尝试要求宝石的名称,但如果您未使用该文件结构,则无法找到要包含的文件。

+0

Chris-非常感谢 - 那就是它 – Yarin

相关问题