我正在尝试在 Rails 中安装机架应用程序,但它不工作。我已经尽可能地重新创建了我的问题的最简单版本。我正在使用 Ruby 1.9.3p327 和 Rails 3.2.11。
我首先使用rails new problem_example
. 切换到problem_example 目录后,我可以访问我的rails 应用程序,http://localhost:3000
并且生活很棒。
按照Rack in Rails 3 Railscast中的说明,我将以下内容添加到我的路线中:
ProblemExample::Application.routes.draw do
root :to => proc { |env| [200, {}, ["Oh yeah!"]] }
end
我还从公用文件夹中删除了 index.html 文件。如果我导航到http://localhost:3000
,我会看到“哦,是的!” 输出到我的屏幕。
这是棘手的部分。如果我修改我的路线看起来像这样:
class SimpleRackApplication
def call(env)
[200, {'Content-Type' => 'text/plain'}, ["Oh no!"]]
end
end
ProblemExample::Application.routes.draw do
root :to => SimpleRackApplication
end
我跑了rails s
,我得到了这个严重的错误:
=> Booting WEBrick
=> Rails 3.2.11 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/actionpack-3.2.11/lib/action_dispatch/routing/mapper.rb:181:in `default_controller_and_action': missing :controller (ArgumentError)
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/actionpack-3.2.11/lib/action_dispatch/routing/mapper.rb:78:in `normalize_options!'
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/actionpack-3.2.11/lib/action_dispatch/routing/mapper.rb:61:in `initialize'
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/actionpack-3.2.11/lib/action_dispatch/routing/mapper.rb:1304:in `new'
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/actionpack-3.2.11/lib/action_dispatch/routing/mapper.rb:1304:in `add_route'
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/actionpack-3.2.11/lib/action_dispatch/routing/mapper.rb:1284:in `decomposed_match'
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/actionpack-3.2.11/lib/action_dispatch/routing/mapper.rb:1270:in `block in match'
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/actionpack-3.2.11/lib/action_dispatch/routing/mapper.rb:1270:in `each'
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/actionpack-3.2.11/lib/action_dispatch/routing/mapper.rb:1270:in `match'
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/actionpack-3.2.11/lib/action_dispatch/routing/mapper.rb:260:in `root'
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/actionpack-3.2.11/lib/action_dispatch/routing/mapper.rb:1317:in `root'
from /Users/landonschropp/Dropbox/Development/current/problem_example/config/routes.rb:9:in `block in <top (required)>'
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/actionpack-3.2.11/lib/action_dispatch/routing/route_set.rb:282:in `instance_exec'
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/actionpack-3.2.11/lib/action_dispatch/routing/route_set.rb:282:in `eval_block'
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/actionpack-3.2.11/lib/action_dispatch/routing/route_set.rb:260:in `draw'
from /Users/landonschropp/Dropbox/Development/current/problem_example/config/routes.rb:8:in `<top (required)>'
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:245:in `load'
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:245:in `block in load'
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:236:in `load_dependency'
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:245:in `load'
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/application/routes_reloader.rb:40:in `each'
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/application/routes_reloader.rb:40:in `load_paths'
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/application/routes_reloader.rb:16:in `reload!'
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/application/routes_reloader.rb:26:in `block in updater'
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/file_update_checker.rb:78:in `call'
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/file_update_checker.rb:78:in `execute'
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/application/routes_reloader.rb:27:in `updater'
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/application/routes_reloader.rb:7:in `execute_if_updated'
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/application/finisher.rb:66:in `block in <module:Finisher>'
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/initializable.rb:30:in `instance_exec'
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/initializable.rb:30:in `run'
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/initializable.rb:55:in `block in run_initializers'
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/initializable.rb:54:in `each'
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/initializable.rb:54:in `run_initializers'
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/application.rb:136:in `initialize!'
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /Users/landonschropp/Dropbox/Development/current/problem_example/config/environment.rb:5:in `<top (required)>'
from /Users/landonschropp/Dropbox/Development/current/problem_example/config.ru:3:in `require'
from /Users/landonschropp/Dropbox/Development/current/problem_example/config.ru:3:in `block in <main>'
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rack-1.4.4/lib/rack/builder.rb:51:in `instance_eval'
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rack-1.4.4/lib/rack/builder.rb:51:in `initialize'
from /Users/landonschropp/Dropbox/Development/current/problem_example/config.ru:in `new'
from /Users/landonschropp/Dropbox/Development/current/problem_example/config.ru:in `<main>'
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rack-1.4.4/lib/rack/builder.rb:40:in `eval'
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rack-1.4.4/lib/rack/builder.rb:40:in `parse_file'
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rack-1.4.4/lib/rack/server.rb:200:in `app'
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/commands/server.rb:46:in `app'
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rack-1.4.4/lib/rack/server.rb:304:in `wrapped_app'
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rack-1.4.4/lib/rack/server.rb:254:in `start'
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/commands/server.rb:70:in `start'
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/commands.rb:55:in `block in <top (required)>'
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/commands.rb:50:in `tap'
from /Users/landonschropp/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/commands.rb:50:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
这是怎么回事?