"-6ren">
gpt4 book ai didi

ruby-on-rails - Heroku 网站因 Rails 3.2.9 和路由约束而崩溃

转载 作者:数据小太阳 更新时间:2023-10-29 07:17:53 26 4
gpt4 key购买 nike

我的网站托管在 Heroku 中,在 Rails 3.2.8 上运行良好。我正在为静态(大部分)网页使用带有 HighVoltage gem 的路由约束类:路线.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.9 并执行了 git 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 类。我在 routes.rb 的顶部有 required:

require 'constraints/static_page'

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

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

最佳答案

你能在你的 Gemfile 中尝试以下版本吗:

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

# ...

High Voltage 的 1.2.1 版本内置了根路由约束。这将允许您从 config/routes.rb 文件中完全删除路由。

只需为高压设置一个初始化器:

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

我将以上内容部署到 Heroku 上的 Cedar 应用程序,它按预期运行。

关于ruby-on-rails - Heroku 网站因 Rails 3.2.9 和路由约束而崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13386828/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com