17

I noticed that the new version of Michael Hartl's Ruby on Rails Tutorial says to include the following to serving static assets on Heroku

gem 'rails_12factor', group: :production

The previous version of his book did not have that. Can someone explain the details of what happened with Heroku that requires this gem?

user782220
  • 10,677
  • 21
  • 72
  • 135
  • 1
    It is related to how logging is done there https://devcenter.heroku.com/articles/rails4 – taro Nov 01 '13 at 09:01
  • When did the change to logging behavior on Heroku happen? – user782220 Nov 01 '13 at 09:48
  • I believe, they always had this kind of logging, but previously they injected some code into application automatically. I advise you read the source code of the gem if you're really interested. – taro Nov 01 '13 at 09:51
  • Is there a post where Heroku says they are stopping the injection of the code? – user782220 Nov 01 '13 at 22:31

6 Answers6

8

The best answer I could find is by looking at the rails_12factor README.

There's also a discussion on why Heroku decided to include the gem: Why does this gem exist? Especially read the answer from schneems about halfway down the page.

Dennis
  • 56,821
  • 26
  • 143
  • 139
Daniel
  • 2,950
  • 2
  • 25
  • 45
4

This gem enables serving assets in production and setting your logger to standard out, both of which are required to run a Rails 4 application on a twelve-factor provider. The gem also makes the appropriate changes for Rails 3 apps.

Shoaib Malik
  • 373
  • 4
  • 8
  • What if you're not using the asset pipeline? – John Judd Feb 14 '14 at 07:31
  • 1
    that's an odd question. Rails offers much more than the asset pipeline to the developer. There's also legacy code to consider. In my case I was/am working on pre-asset pipeline code. – John Judd Dec 04 '14 at 03:50
4

In the Getting Started with Rails 4.x on Heroku, we can read this:

Heroku integration has previously relied on using the Rails plugin system, which has been removed from Rails 4. To enable features such as static asset serving and logging on Heroku please add rails_12factor gem to your Gemfile.

DLight
  • 1,535
  • 16
  • 20
2

Older question, but FWIW Rails 5 Apps do not require the rails_12factor gem. Per the README:

We worked with the Rails core team to make Rails 5 work on twelve-factor platforms out of the box.

There is also a snippet for migrating to Rails 5.

jdgray
  • 1,863
  • 1
  • 11
  • 19
0

Just ran into a problem with a Rails 4 application on Heroku and couldn't debug it with heroku run logs. Without the rails12factor gem, you can't see the full logs that you normally see on your console in development. I was getting a 500 error and there wasn't any available information.

It actually didn't tell me that migrations were pending without rails12factor

Ka Mok
  • 1,937
  • 3
  • 22
  • 47
0

As of Rails 5, you no longer need to include this gem in your Gemfile. They've removed it from their documentation also: https://github.com/railsbridge/docs/issues/569

aarona
  • 35,986
  • 41
  • 138
  • 186