195 points · by mhartl · 13y ago · 44 comments
Should I start with this (4.0) tutorial?
Railstutorial was a key part in that, a brilliantly written resource which helps explain lots of complex concepts in simple ways. Very excited to see the new Rails 4 version come out. I cannot recommend this highly enough to people who are starting from scratch with Rails.
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.You need the cedar stack for the ruby directive to work on the Gemfile
Anyone trying to learn RoR, use this guy's tutorial - promise you won't regret it!
I'm also finding that reading open source code is giving me some much needed 'real-world' exposure - currently studying Lobsters (https://github.com/jcs/lobsters)
I have spoken with many dozens of other beginners at local Ruby meetups. Basically EVERYONE learning Rails and Ruby (at least in NYC) uses this thing.
It might not be a bad idea to read through the Rails Tutorial, even if you're an experienced Rails developer, just to see what the baseline is for people starting out these days.
Very much appreciated, Michael!
As others have said, thank you so much for this resource. Everyone who can afford it who finds it useful should purchase it (I bought v3.0 on Kindle, and v3.2 in hard copy)
Glad you like the book!
Thanks for these!