Rails 3 在“lib"中看不到我的类目录 [英] Rails 3 does not see my class in "lib" directory

查看:47
本文介绍了Rails 3 在“lib"中看不到我的类目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将文件 rack_app.rb 和简单的 Rack 应用程序放在 lib 目录中:

I've placed the file rack_app.rb with simple Rack application in the lib directory:

class RackApp
  def call env
    [200, {}, 'Hello']
  end
end

然后我添加了这条路线:

Then I've added this route:

match 'rack' => RackApp

当我尝试启动 rails 服务器时,我收到以下错误:

And when I try to launch the rails server I get the following error:

config/routes.rb:65: 未初始化的常量 RackApp (NameError)

推荐答案

Rails 3 默认不再自动加载.所以你需要你的文件

Rails 3 has no more autoloading by default. So you need require your file

require 'lib/rack_app.rb'

或者在 application.rb 中返回自动加载

Or come back the autoloading in application.rb

config.autoload_paths += %W( #{config.root}/lib )

这篇关于Rails 3 在“lib"中看不到我的类目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆