5

我的网站托管在 Heroku 中,在 Rails 3.2.8 上运行良好。我正在为静态(主要)网页使用带有 HighVoltage gem 的路由约束类:routes.rb:

get "/*id" => "high_voltage/pages#show", constraints: Constraints::StaticPage.new

我有一个文件/lib/constraints/static_page.rb

module Constraints
  class StaticPage
    def matches?(request)
      File.exist? file_path(request.path)
    end

    private

    def file_path(view)
      static_page_views_dir.to_s.concat("#{view}.html.erb")
    end

    def static_page_views_dir
      Rails.root.join('app', 'views', 'pages')
    end
  end
end

问题是,我刚刚更新到 Rails 3.2.9git push heroku并且我的应用程序崩溃了:(

my-host:my-site scott$ heroku ps
=== web: `bundle exec rails server -p $PORT`
web.1: crashed 2012/11/14 12:14:41 (~ 2s ago)

显然,Ruby/Heroku 找不到我的Constraints::StaticPage班级。我把它require放在我的顶部routes.rb

require 'constraints/static_page'

Rails 3.2.9 中是否发生了一些变化,以至于不再适用于 Heroku?在本地一切正常,只是在 Heroku 中不行。如果我在我的路线中去掉那个约束,一切都会完美(除了没有这些约束)。这是我的heroku logs输出:

2012-11-14T20:14:36+00:00 app[web.1]: DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/config/environment.rb:5)
2012-11-14T20:14:36+00:00 app[web.1]: DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/config/environment.rb:5)
2012-11-14T20:14:38+00:00 app[web.1]: => Booting WEBrick
2012-11-14T20:14:38+00:00 app[web.1]: => Rails 3.2.9 application starting in production on http://0.0.0.0:18361
2012-11-14T20:14:38+00:00 app[web.1]: => Call with -d to detach
2012-11-14T20:14:38+00:00 app[web.1]: => Ctrl-C to shutdown server
2012-11-14T20:14:38+00:00 app[web.1]: Exiting
2012-11-14T20:14:38+00:00 app[web.1]: /app/config/routes.rb:50:in `block in <top (required)>': uninitialized constant ActionDispatch::Routing::Mapper::Constraints::StaticPage (NameError)
2012-11-14T20:14:38+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.9/lib/action_dispatch/routing/route_set.rb:282:in `instance_exec'
2012-11-14T20:14:38+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.9/lib/action_dispatch/routing/route_set.rb:282:in `eval_block'
2012-11-14T20:14:38+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.9/lib/action_dispatch/routing/route_set.rb:260:in `draw'
2012-11-14T20:14:38+00:00 app[web.1]:   from /app/config/routes.rb:3:in `<top (required)>'
2012-11-14T20:14:38+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
2012-11-14T20:14:38+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/application/routes_reloader.rb:40:in `each'
2012-11-14T20:14:38+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/lazy_load_hooks.rb:34:in `execute_hook'
2012-11-14T20:14:38+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks'
2012-11-14T20:14:38+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/lazy_load_hooks.rb:42:in `each'
2012-11-14T20:14:38+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
2012-11-14T20:14:38+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/application/finisher.rb:52:in `block in <module:Finisher>'
2012-11-14T20:14:38+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/application/routes_reloader.rb:40:in `load_paths'
2012-11-14T20:14:38+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/devise-2.1.2/lib/devise/rails.rb:14:in `block in <class:Engine>'
2012-11-14T20:14:38+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/application/routes_reloader.rb:16:in `reload!'
2012-11-14T20:14:38+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/application.rb:108:in `reload_routes!'
2012-11-14T20:14:38+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/lazy_load_hooks.rb:34:in `call'
2012-11-14T20:14:38+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/initializable.rb:55:in `block in run_initializers'
2012-11-14T20:14:38+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/initializable.rb:54:in `run_initializers'
2012-11-14T20:14:38+00:00 app[web.1]:   from /app/config/environment.rb:5:in `<top (required)>'
2012-11-14T20:14:38+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/railtie/configurable.rb:30:in `method_missing'
2012-11-14T20:14:38+00:00 app[web.1]:   from /app/config.ru:4:in `block in <main>'
2012-11-14T20:14:38+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/application.rb:136:in `initialize!'
2012-11-14T20:14:38+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/initializable.rb:54:in `each'
2012-11-14T20:14:38+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:51:in `instance_eval'
2012-11-14T20:14:38+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/initializable.rb:30:in `run'
2012-11-14T20:14:38+00:00 app[web.1]:   from /app/config.ru:1:in `new'
2012-11-14T20:14:38+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:51:in `initialize'
2012-11-14T20:14:38+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/initializable.rb:30:in `instance_exec'
2012-11-14T20:14:38+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/commands.rb:50:in `tap'
2012-11-14T20:14:38+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/commands.rb:50:in `<top (required)>'
2012-11-14T20:14:38+00:00 app[web.1]:   from /app/config.ru:1:in `<main>'
2012-11-14T20:14:38+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:40:in `eval'
2012-11-14T20:14:38+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:40:in `parse_file'
2012-11-14T20:14:38+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:200:in `app'
2012-11-14T20:14:38+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/commands/server.rb:46:in `app'
2012-11-14T20:14:38+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:301:in `wrapped_app'
2012-11-14T20:14:38+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:252:in `start'
2012-11-14T20:14:38+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/commands/server.rb:70:in `start'
2012-11-14T20:14:38+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/commands.rb:55:in `block in <top (required)>'
2012-11-14T20:14:38+00:00 app[web.1]:   from script/rails:6:in `require'
2012-11-14T20:14:38+00:00 app[web.1]:   from script/rails:6:in `<main>'
2012-11-14T20:14:40+00:00 heroku[web.1]: Process exited with status 1
2012-11-14T20:14:40+00:00 heroku[web.1]: State changed from starting to crashed
4

1 回答 1

3

Can you try out the following versions in your Gemfile:

# Gemfile
gem 'rails', '3.2.9'
gem 'high_voltage', '~> 1.2.1'
gem 'thin'

# ...

The 1.2.1 release of High Voltage has the root route constraints baked into it. This will allow you to remove the routes completely from your config/routes.rb file.

Just set up an initializer for High Voltage:

# config/initializers/high_voltage.rb
HighVoltage.route_drawer = HighVoltage::RouteDrawers::Root

I deployed the above to a Cedar app on Heroku and it ran as expected.

于 2012-11-14T21:22:05.183 回答