Heroku Cedar Rails 3.1 db:迁移失败
我是第一次使用 Heroku,第一次使用 Postgres 新手,在部署到 Heroku 时遇到一些困难。
我的应用程序在我的机器上运行良好,但当我尝试访问 myapp.heroku.com 时,我得到 status=500。
到目前为止我的步骤:
$ lunchy start postgres
$ createdb -Ouser -Eutf8 myapp_development
$ createdb -Ouser -Eutf8 myapp_test
$ rails new myapp --development=postgresql
$ cd myapp
$ git init
$ git add .
$ git commit -m "init"
$ git push -u origin master
$ heroku create --stack cedar
$ git push heroku master
>>>>Some simple app scaffolding<<<<<
$ git add .
$ git commit -m "simple scaffolding"
$ git push
$ git push heroku
$ heroku run rake db:migrate
该命令似乎已运行,但没有看到任何正在创建的表。
Procfile 内容:
web: bundle exec thin start -p $PORT -e $RACK_ENV
heroku 日志显示:
2011-11-18T08:01:28+00:00 app[run.6]: Awaiting client
2011-11-18T08:01:28+00:00 app[run.6]: Starting process with command `bundle exec rake db:migrate`
2011-11-18T08:01:29+00:00 heroku[run.6]: State changed from starting to up
2011-11-18T08:01:33+00:00 heroku[run.6]: Process exited
2011-11-18T08:01:35+00:00 heroku[run.6]: State changed from up to complete
2011-11-18T08:03:21+00:00 heroku[router]: GET myapp.herokuapp.com/ dyno=web.1 queue=0 wait=0ms service=9ms status=500 bytes=728
2011-11-18T08:03:23+00:00 heroku[router]: GET myapp.herokuapp.com/favicon.ico dyno=web.1 queue=0 wait=0ms service=17ms status=304 bytes=0
2011-11-18T08:04:18+00:00 app[web.1]:
2011-11-18T08:04:18+00:00 app[web.1]:
2011-11-18T08:04:18+00:00 app[web.1]: Started GET "/" for 101.171.144.139 at 2011-11-18 08:04:18 +0000
2011-11-18T08:04:18+00:00 app[web.1]: Processing by PagesController#home as HTML
2011-11-18T08:04:18+00:00 app[web.1]: Rendered pages/home.html.erb within layouts/application (0.2ms)
2011-11-18T08:04:18+00:00 app[web.1]: Rendered layouts/_head.html.erb (0.9ms)
2011-11-18T08:04:18+00:00 app[web.1]: Completed 500 Internal Server Error in 2ms
2011-11-18T08:04:18+00:00 app[web.1]:
2011-11-18T08:04:18+00:00 app[web.1]: ActionView::Template::Error (custom.css isn't precompiled):
2011-11-18T08:04:18+00:00 app[web.1]: 7: <meta name="viewport" content="width=device-width" />
2011-11-18T08:04:18+00:00 app[web.1]: 8: <title><%= title %></title>
2011-11-18T08:04:18+00:00 app[web.1]: 9: <%= stylesheet_link_tag "application" %>
2011-11-18T08:04:18+00:00 app[web.1]: 10: <%= stylesheet_link_tag 'custom', :media => 'screen' %>
2011-11-18T08:04:18+00:00 app[web.1]: 11: <%= javascript_include_tag "application" %>
2011-11-18T08:04:18+00:00 app[web.1]: 12: <%= csrf_meta_tags %>
2011-11-18T08:04:18+00:00 app[web.1]: 13: </head>
2011-11-18T08:04:18+00:00 app[web.1]: app/views/layouts/_head.html.erb:10:in `_app_views_layouts__head_html_erb___3427718828002391478_29348560'
2011-11-18T08:04:18+00:00 app[web.1]: app/views/layouts/application.html.erb:4:in `_app_views_layouts_application_html_erb___1135382871397557001_29029960'
2011-11-18T08:04:18+00:00 app[web.1]:
2011-11-18T08:04:18+00:00 heroku[router]: GET myapp.herokuapp.com/ dyno=web.1 queue=0 wait=0ms service=13ms status=500 bytes=728
2011-11-18T08:04:18+00:00 app[web.1]:
2011-11-18T08:04:18+00:00 app[web.1]: cache: [GET /] miss
2011-11-18T08:04:19+00:00 app[web.1]: cache: [GET /favicon.ico] stale, invalid, store
我有一个 custom.css 未预编译,所以我将
$ RAILS_ENV=production bundle exec rake assets:precompile
其预编译到 public/assets 中。然后重新执行
$ git add.
$ git push
$ git heroku push
$ heroku rake db:migrate
$ heroku open
Rerun,但日志中仍然出现相同的错误。
我做错了什么?
Gemfile:
gem 'rails', '3.1.1'
gem 'pg'
gem 'thin'
gem 'foreman'
gem 'heroku'
group :development do
gem 'rspec-rails'
end
group :test do
gem 'rspec-rails'
gem 'webrat'
end
group :assets do
gem 'sass-rails', '~> 3.1.4'
gem 'coffee-rails', '~> 3.1.1'
gem 'uglifier', '>= 1.0.3'
gem 'zurb-foundation'
end
gem 'jquery-rails'
database.yml:
development:
adapter: postgresql
encoding: unicode
database: myapp_development
pool: 5
username: user
password: password
test:
adapter: postgresql
encoding: unicode
database: myapp_test
pool: 5
username: user
password: password
production:
adapter: postgresql
encoding: unicode
database: myapp_production
pool: 5
username: user
password: password
Production.rb:
MyApp::Application.configure do
config.cache_classes = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = false
config.assets.compress = true
config.assets.compile = false
config.assets.digest = true
end
I'm a first-time heroku, first-time postgres newbie and am having some difficulties deploying to heroku.
My app is working fine on my machine but I get a status=500 when I try to access myapp.heroku.com.
My steps thus far:
$ lunchy start postgres
$ createdb -Ouser -Eutf8 myapp_development
$ createdb -Ouser -Eutf8 myapp_test
$ rails new myapp --development=postgresql
$ cd myapp
$ git init
$ git add .
$ git commit -m "init"
$ git push -u origin master
$ heroku create --stack cedar
$ git push heroku master
>>>>Some simple app scaffolding<<<<<
$ git add .
$ git commit -m "simple scaffolding"
$ git push
$ git push heroku
$ heroku run rake db:migrate
The command seems to run but a don't see any tables being created.
Procfile contents:
web: bundle exec thin start -p $PORT -e $RACK_ENV
The heroku log shows:
2011-11-18T08:01:28+00:00 app[run.6]: Awaiting client
2011-11-18T08:01:28+00:00 app[run.6]: Starting process with command `bundle exec rake db:migrate`
2011-11-18T08:01:29+00:00 heroku[run.6]: State changed from starting to up
2011-11-18T08:01:33+00:00 heroku[run.6]: Process exited
2011-11-18T08:01:35+00:00 heroku[run.6]: State changed from up to complete
2011-11-18T08:03:21+00:00 heroku[router]: GET myapp.herokuapp.com/ dyno=web.1 queue=0 wait=0ms service=9ms status=500 bytes=728
2011-11-18T08:03:23+00:00 heroku[router]: GET myapp.herokuapp.com/favicon.ico dyno=web.1 queue=0 wait=0ms service=17ms status=304 bytes=0
2011-11-18T08:04:18+00:00 app[web.1]:
2011-11-18T08:04:18+00:00 app[web.1]:
2011-11-18T08:04:18+00:00 app[web.1]: Started GET "/" for 101.171.144.139 at 2011-11-18 08:04:18 +0000
2011-11-18T08:04:18+00:00 app[web.1]: Processing by PagesController#home as HTML
2011-11-18T08:04:18+00:00 app[web.1]: Rendered pages/home.html.erb within layouts/application (0.2ms)
2011-11-18T08:04:18+00:00 app[web.1]: Rendered layouts/_head.html.erb (0.9ms)
2011-11-18T08:04:18+00:00 app[web.1]: Completed 500 Internal Server Error in 2ms
2011-11-18T08:04:18+00:00 app[web.1]:
2011-11-18T08:04:18+00:00 app[web.1]: ActionView::Template::Error (custom.css isn't precompiled):
2011-11-18T08:04:18+00:00 app[web.1]: 7: <meta name="viewport" content="width=device-width" />
2011-11-18T08:04:18+00:00 app[web.1]: 8: <title><%= title %></title>
2011-11-18T08:04:18+00:00 app[web.1]: 9: <%= stylesheet_link_tag "application" %>
2011-11-18T08:04:18+00:00 app[web.1]: 10: <%= stylesheet_link_tag 'custom', :media => 'screen' %>
2011-11-18T08:04:18+00:00 app[web.1]: 11: <%= javascript_include_tag "application" %>
2011-11-18T08:04:18+00:00 app[web.1]: 12: <%= csrf_meta_tags %>
2011-11-18T08:04:18+00:00 app[web.1]: 13: </head>
2011-11-18T08:04:18+00:00 app[web.1]: app/views/layouts/_head.html.erb:10:in `_app_views_layouts__head_html_erb___3427718828002391478_29348560'
2011-11-18T08:04:18+00:00 app[web.1]: app/views/layouts/application.html.erb:4:in `_app_views_layouts_application_html_erb___1135382871397557001_29029960'
2011-11-18T08:04:18+00:00 app[web.1]:
2011-11-18T08:04:18+00:00 heroku[router]: GET myapp.herokuapp.com/ dyno=web.1 queue=0 wait=0ms service=13ms status=500 bytes=728
2011-11-18T08:04:18+00:00 app[web.1]:
2011-11-18T08:04:18+00:00 app[web.1]: cache: [GET /] miss
2011-11-18T08:04:19+00:00 app[web.1]: cache: [GET /favicon.ico] stale, invalid, store
I got an custom.css isn't precompiled so I did
$ RAILS_ENV=production bundle exec rake assets:precompile
This pre-compiled into public/assets. Then re-did
$ git add.
$ git push
$ git heroku push
$ heroku rake db:migrate
$ heroku open
Rerun and still get the same error in the logs.
What am I doing wrong?
Gemfile:
gem 'rails', '3.1.1'
gem 'pg'
gem 'thin'
gem 'foreman'
gem 'heroku'
group :development do
gem 'rspec-rails'
end
group :test do
gem 'rspec-rails'
gem 'webrat'
end
group :assets do
gem 'sass-rails', '~> 3.1.4'
gem 'coffee-rails', '~> 3.1.1'
gem 'uglifier', '>= 1.0.3'
gem 'zurb-foundation'
end
gem 'jquery-rails'
database.yml:
development:
adapter: postgresql
encoding: unicode
database: myapp_development
pool: 5
username: user
password: password
test:
adapter: postgresql
encoding: unicode
database: myapp_test
pool: 5
username: user
password: password
production:
adapter: postgresql
encoding: unicode
database: myapp_production
pool: 5
username: user
password: password
Production.rb:
MyApp::Application.configure do
config.cache_classes = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = false
config.assets.compress = true
config.assets.compile = false
config.assets.digest = true
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要将预编译资源推送到 git。
运行
bundle exec rake assets:precompile
后,执行git add .
,最后执行git push heroku master
。You need to push the precompiled assets to git.
After running
bundle exec rake assets:precompile
, do agit add .
and finallygit push heroku master
.实际上,您可以在 Cedar 上无需预编译资源,请参阅以下内容:
“在运行时编译资源”
http://devcenter.heroku.com/articles/rails31_heroku_cedar
您需要设置以下内容在你的生产.rb中:
config.assets.compile = false
以便在编译 slug 时对其进行编译。
You can actually get by without precompiled assets on Cedar, see the following:
"Compiling assets during runtime" at
http://devcenter.heroku.com/articles/rails31_heroku_cedar
You'll want to set the following in your production.rb:
config.assets.compile = false
in order to get it to compile while it's compiling the slug.