Hacker News new | past | comments | ask | show | jobs | submit login
The Ruby on Rails Tutorial for Rails 4.0 (beta) (railstutorial.org)
195 points by mhartl on March 20, 2013 | hide | past | favorite | 44 comments



Hartl's Rails Tutorial is by far the best and most pragmatic programming tutorial I have ever read. I used it to get me started with Rails 3 (bought the hard copy) and I still consult it all the time when working in Rails. I have never felt so empowered as a programmer the first time I build that twitter clone from the tutorial. It didn't teach me anything about algorithms, databases, or any of the core things I learn in school. Instead it taught me serious practical things like deployment, rapid prototyping, version control, and so much more. Michael, if you're still reading this thread: Thank You. You made programming exciting for me.


Thanks for sharing your story. Glad to hear it! :-)


I was just about to start the tutorial for this reason. I don't have any Rails experience but I've been learning basic Ruby.

Should I start with this (4.0) tutorial?


Yes, the Rails Tutorial and RailsCasts episodes should get you up to speed and keep you up to date. IMHO, they're the best learning resources for RoR out there.


Yeah, sorry, what I meant was that I'm definitely set on doing the tutorial. I'm just not sure if I should go through the 4.0 draft or the older version that's been up there. Would it be more practical to learn on 4.0?


They're not that different, so if you're just starting out I recommend following the more stable 3.2 version. Once you've finished that, you'll be in a position to learn the Rails 4.0–specific material very quickly (especially once the supplementary screencast comes out).


The older version, 3.2, should be more stabler but it may be worth the slight risk to learn 4.0 from the start, as that will provide you with newer feature overviews of the framework. If you do have troubles with 4.0, you can ask and find answers on StackOverflow or the #rubyonrails IRC. You may also help by reporting any errors or bugs in 4.0.


I agree. Having been suddenly thrusted into the world of Ruby, Rails (and web development in general) from Java and C, Micheal's tutorial was a real life saver. I would have been lost in the crowd had it not been for this. Excellent!


Totally agree. Tried a few other things before it and so few get the balance of explaining enough 'why' to make a task not arbitrary, while also keeping you grounded in the practical stuff you actually need to know.


I hadn't don't any programming since some BASIC and Fortran during my physics degree in the mid 90s until 2010 when the loss of a technical co-founder in back to back startups made me recognize I needed to make myself my own technical cofounder - at least to get through the MVP phase. I'm writing a blog post about this at the moment including links to the key resources that helped me go from a sales, marketing, biz dev guy to competent developer able to produce my own MVPs.

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.


Looking forward to your post! Add a link when you do, please!


   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


Even with an explicit Ruby line in the Gemfile, I get this error:

    $ 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.


Interesting.

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.


Thanks. Yes, I just realized that it's "working", even though it shows an error. See https://news.ycombinator.com/item?id=5411968.

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.


That's weird. http://www.cupidwithfriends.com is running rails 4 and been on heroku for the past week. Our Gemfile:

    source 'https://rubygems.org'

    ruby '1.9.3'

    # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
    gem 'rails', '4.0.0.beta1'


Thanks. I think I know what the problem is. Tracking it down now...

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.


> Instead, something magical happens, and the magic doesn't work on Heroku.

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're right, of course, but it's not just that. In previous versions of Rails, the default page (a static file served out of the public/ directory) worked just fine on Heroku. It was only the magical “About your application’s environment” link that didn't work. In Rails 4.0, the static file is gone, and as far as I can tell the entire default page is magic, so on Heroku it breaks in its entirety, too.

It's not a big deal of course, as in any real app you'll quickly define a root route and be done with it. (I do consider it a feature, too, as I really like not having to remove the static file by hand.)


Try following these instructions: https://gist.github.com/peter/3025502.


Thanks! That link had the missing piece, which is to configure Rails to serve static assets. See https://news.ycombinator.com/item?id=5411968.


Are you running on the cedar stack? heroku stack

You need the cedar stack for the ruby directive to work on the Gemfile


Are you running a Cedar or Bamboo app? Ruby 2.0.0 only works on Cedar.


All right, based on everyone's feedback I was able to get things working on Heroku and have updated the news post and book accordingly. Thanks! HN rocks.


Great stuff. The Rails Tutorial was my top resource when learning Rails and I still use it as a reference (along with RailsSpace and Railscasts). I'm using Rails 4 on a few projects, so if I can lend any feedback on the future release let me know.


Please do send feedback! Any significant structural changes will have to wait until the next full edition (slated for production later this year), but bug and typo reports are hugely appreciated. I typically process such reports as an email queue, so send them to admin@railstutorial.org.


Just started learning rails last week, and I have say Michael, you have been a huge key part of that. My boss thanks you for speeding up my learning process. Your book actually just arrived today.

Anyone trying to learn RoR, use this guy's tutorial - promise you won't regret it!


I'm working through it now - have left the tutorial for a while (finished chapter 8, sign in) to do a few demo projects and make sure all the concepts are sticking.

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 did the rails 3.0 version of this tutorial about 2 years ago. Highly highly recommended. It almost single-handedly got me into web development and I certainly wouldn't be where I am today without it. Many thanks mhartl.



I started learning to code last year using Hartl's Rails Tutorial. It was actually a big part of me deciding to go with Ruby and Rails over any other language and framework.

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!


I don't think there has been a single more valuable resource in my learning to build web applications. Thanks for your work, Michael.


My version of rails 4.0 won't work without ruby 2.0 but I'm not complaining. Works like a charm as far as I have tested it.


Can you expand on 'won't work?' Did you / can you file a ticket? Rails 4.0 should work on Ruby 1.9.3, though we do recommend 2.0.


I've done two versions of the Hartl Rails tutorials now, looks like I'll be doing a third. They really are truly excellent resources, and if anyone is considering doing an in-depth tutorial for any technology there's plenty of lessons to be had there. I recommend it constantly to people who're looking to get a start with Rails.


As I read the post (haven't dug into the v4 book itself yet), this covers only revisions, not new features (such as TurboLinks)?

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)


Completely new features like TurboLinks aren't covered yet (they will probably be in the full third edition later this year), but additions like strong parameters and the new Active Record finders are covered.

Glad you like the book!


Since there are by now probably a lot of readers who go back to the book and user it as a reference, is there any chance that you include new topics / extra chapters with more advanced topics? Would be great (+ you could charge me again... ;-).


@mhartl I noticed you recently got a Chinese translation for the tut. Are there any other language translations available or in the works? (I'm looking Portuguese or even Spanish secondarily)


I basically learned rails from the first tutorial.

Thanks for these!


I think a mobile web application example would be great to include in this awesome tutorial.


I LOVE this tutorial. Read it twice, definitely going to read this one.


What about Pjax, Russian Doll Caching, Ruby 2.0 etc?


Congrats, Michael!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: