Rails 4 on Heroku Share

4035ddfe11dbb2afc4e683b1bc6ac68f
huacnlee 2016-03-25 05:46:49 UTC

This article covers how to run a Ruby on Rails application on Heroku. It assumes a knowledge of both Heroku and with Rails. If you are new to either please see the Getting Started with Rails 4.x on Heroku instead. This article assumes that you have a copy of the Heroku Toolbelt installed locally.

Most of Rails works out of the box with Heroku, however there are a few things you can do to get the most out of the platform. To do this you will need to configure your Rails 4 app to connect to Postgres, your logs need to be configured to point to STDOUT, and your application needs to have serving assets enabled in production.

Logging and assets

Heroku treats logs as streams and requires your logs to be sent to STDOUT. To enable STDOUT logging in Rails 4 you can add the rails_12factor gem. This gem will also configure your app to serve assets in production. To add this gem add this to your Gemfile:

This gem allows you to bring your application closer to being a 12factor application. You can get more information about how the gem configures logging and assets read the rails_12factor README. If this gem is not present in your application, you will receive a warning while deploying, and your assets and logs will not be functional.

Postgres

Your application needs to be configured to use the Postgres database. Newly generated Rails 4 applications are configured to use sqlite. To use Postgres instead add the pg gem to your Gemfile:

gem 'pg'

We recommend using the same database in development and production to maintain dev/prod parity. You will need to remove the sqlite gem from your gemfile or place it in a non production group. You can read more about why you should not run sqlite on Heroku, which also contains detailed instructions on setting up Postgres locally.

E78ac384856c23c94c3ff3d1383cdd9f
442453867 2016-03-25 08:48:13 UTC

11111

E78ac384856c23c94c3ff3d1383cdd9f
442453867 2016-03-25 08:48:25 UTC

22222

E78ac384856c23c94c3ff3d1383cdd9f
442453867 2016-03-25 08:48:29 UTC

33333

E78ac384856c23c94c3ff3d1383cdd9f
442453867 2016-03-25 08:48:34 UTC

44444

7bd8dafdf90ce66d41d1a7ad9de89dea
asfasf 2016-03-31 11:55:10 UTC

fff

Bb34a5c0a3c3b450b4bf5c288b449292
2243980491 2016-04-08 06:02:00 UTC

666

D219af79b45e5891507fda4c4c2139a0
1 2016-11-21 14:59:53 UTC

1111

D219af79b45e5891507fda4c4c2139a0
1 2016-11-28 09:28:11 UTC

KJKJJKHGJHF

0581317f47f0d73519f2478c654a4833
3131874349 2017-03-12 03:55:29 UTC

gykg

0581317f47f0d73519f2478c654a4833
3131874349 2017-03-12 03:55:54 UTC

回答说了的