by sync · 13y ago · 0 comments
Finally, as far as I can tell Rails 4 doesn’t yet work on Heroku,
so all the deployment examples currently fail.
Rails 4 definitely works on heroku, what problems are you seeing?Edit: You may be missing "ruby '2.0.0'" or "ruby '1.9.3'" in your Gemfile, as seen in: https://gist.github.com/speedmanly/d15a3a5f8d0971bc0c92
$ heroku logs
.
.
.
heroku[slugc]: Slug compilation failed: unrecognized error
Here's the Gemfile: source 'https://rubygems.org'
ruby '2.0.0'
gem 'rails', '4.0.0.beta1'
group :development do
gem 'sqlite3', '1.3.7'
end
group :assets do
gem 'sass-rails', '4.0.0.beta1'
gem 'coffee-rails', '4.0.0.beta1'
gem 'uglifier', '1.0.3'
end
gem 'jquery-rails', '2.2.1'
gem 'turbolinks', '1.0.0'
gem 'jbuilder', '1.0.1'
group :production do
gem 'pg', '0.14.1'
end
The app is the "first_app" from the book, which is basically the result of running "rails new first_app" plus a slightly modified Gemfile. The full repo is here: https://github.com/mhartl/first_app. Any help in getting it to work on Heroku would be much appreciated.Without making any modifications to your app I have it working on heroku: http://safe-harbor-9177.herokuapp.com
Here's the full output: https://gist.github.com/speedmanly/1099b37338745ccb5a26
Adding a Procfile is generally recommended (although heroku will add a default one)
web: bundle exec rails server thin -p $PORT -e $RACK_ENV
Setting your rails env is a good idea too: heroku config:add RAILS_ENV=production
Note I didn't perform those steps to get the app running, they are just recommended.Edit: Actually I do see this line in my heroku logs:
2013-03-21T00:50:21+00:00 heroku[web.1]: Starting process with command `bin/rails server -p 32752 -e $RAILS_ENV`
2013-03-21T00:50:22+00:00 app[web.1]: bash: bin/rails: No such file or directory
Adding a Procfile should fix that. Listing 'thin' (or another rails server, e.g. unicorn,puma) in your Gemfile is a good practice as well.This is new behavior in Rails 4.0, which is why it threw me. The default page works on Heroku going back to Rails 2.3, but they switched things up in the latest version of Rails.
source 'https://rubygems.org'
ruby '1.9.3'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.0.beta1'Edit: Yes, I figured it out. In Rails 4.0, the default page for a new app is no longer served as a static file from the public/ directory. Instead, something magical happens, and the magic doesn't work on Heroku. That's no worry, though, as it only means the first app doesn't work. The other apps, which set root routes, should work fine.
They don't, though. I can't get the main sample app's CSS or images to load properly. Hmm... Bleeding edge indeed.
Update: You need to edit the default production.rb file to configure Rails to serve static assets:
config.serve_static_assets = true
Thanks to ninthfrank07 for his link at https://news.ycombinator.com/item?id=5411964 that included the solution.To be clear, this is because the 'Welcome page' shows info about the server, so you NEVER want that accidentally leaked to the world at large by accident, so the route gets disabled in production mode.
You need the cedar stack for the ruby directive to work on the Gemfile