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
Chris-非常感谢 - 那就是它 – Yarin