
Rails 4.0: Final version released - thibaut_barrere
http://weblog.rubyonrails.org/2013/6/25/Rails-4-0-final/
======
obiefernandez
It's always an uphill battle for us (Addison Wesley Professional Ruby Series)
to get official recognition from DHH since we're not part of the pragprog
clique.

The latest rewrite of my book for Rails 4 is available at
[http://leanpub.com/tr4w](http://leanpub.com/tr4w)

Michael Hartl's Rails Tutorial has also been fully updated. See
[http://news.railstutorial.org/ruby-on-rails-tutorial-
rails-4...](http://news.railstutorial.org/ruby-on-rails-tutorial-
rails-4-beta/) for all links to relevant material.

~~~
sshconnection
I'd figure that it's more due to differing opinions on things like Test::Unit
vs Rspec, Haml vs Erb etc than your publisher. Still, not a good excuse to go
unrecognized. RW3 was excellent, and I'm sure 4 is as well. Best of luck.

~~~
stiff
"The Rails 3 Way" certainly wasn't excellent, it was clearly a rushed update
of the original "The Rails Way", it uses a lot of old practices all over the
place and the stuff new in Rails 3 is just added as an afterthought.

~~~
obiefernandez
Author here. It took nearly two years to get that rewrite done. A lot of
things changed in Rails 3 right at the end of our production cycle so
admittedly it was a challenge to get it all to the finish line in the best
possible way. That won't be the case with the new edition. I have a stellar
team helping me get this done properly and we're using the excellent Leanpub
system to release the book incrementally and ensure the finished product is of
the highest quality. Much different situation.

~~~
subpixel
Just ordered tr4w - at leanpub it says "These authors use Leanpub to publish
this book independently." I'm just curious whether that's accurate, since you
refer to Addison-Wesley as "us"? Thanks

~~~
obiefernandez
I have a special arrangement with AW to publish independently via leanpub.
Book will also be on sale via traditional retail channels once the hardcopy is
ready later this year. We view it as separate channels. Traditional retail
hits a different customer segment, especially when you start taking into
account corporate subscribers to Safari and companies that do bulk purchases,
etc.

~~~
subpixel
Thanks for clarifying!

------
steveklabnik
I am so excited, as this is the first major release that I've contributed to!
Thank you so much to all the other people who've put this release together, I
really do think this is the best Rails yet!

[http://contributors.rubyonrails.org/releases/4-0-0/contribut...](http://contributors.rubyonrails.org/releases/4-0-0/contributors)

I mentioned this below, but I'll mention it here, as well: if you have gems
that aren't ready yet for Rails 4, please ping me and let me know if I can
help get them ready somehow. If you maintain a gem and want help running your
tests on Travis against multiple versions of Rails, I can help with that as
well.

<3 <3 <3 <3

~~~
rzendacott
Congratulations! That's truly awesome. Any tips for a novice developer who
would love to start contributing?

~~~
steveklabnik
Thank you! I started less than a year ago, and I was the #13th biggest
contributor here, and received a commit bit a few weeks ago. It's not too hard
to get involved if you'd like!

I wrote up my own personal 'contributing to Rails' guide here:
[http://blog.steveklabnik.com/posts/2012-07-05-how-can-i-
cont...](http://blog.steveklabnik.com/posts/2012-07-05-how-can-i-contribute-
to-ruby-on-rails-)

The official one is here:
[http://edgeguides.rubyonrails.org/contributing_to_ruby_on_ra...](http://edgeguides.rubyonrails.org/contributing_to_ruby_on_rails.html)

The easiest way is to write documentation; that's how I got started. It's not
for everyone, though. The simplest possible way to get involved with writing
code is to pick an open bug on the tracker and fix it.

Like most things, it just gets easier the more you do it. The first one seems
hard, everything seems confusing. But by the time you've done two or three,
you wonder why you ever thought it was difficult.

~~~
rzendacott
Thanks! I'll definitely check out the guides and try to get started!

~~~
steveklabnik
Great! Ping me if you have problems.

~~~
rzendacott
I gave it a shot! [0] Hopefully everything looks okay. The hardest part was
finding an issue. Thanks again for your advice!

[0]
[https://github.com/rails/rails/pull/11193](https://github.com/rails/rails/pull/11193)

------
jpdoctor
Ug. We have a new website that is coming out in about a month. Enough mileage
on 3.2 that it's too painful to consider delaying, but hate the thought of
doing the upgrade later.

Would love opinions from the HN gallery as to whether a delay now saves time
later.

Edit: And thanks to the Rails team for providing me with this conundrum!

Edit2: Thanks for the info and opinions! I'll check back later too.

~~~
jeremymcanally
The upgrade isn't that bad. Nowhere near going 2.x to 3.x.

~~~
johnbellone
Our application is still on 2.x and we were delaying migrating in hopes that
we would have time to actually just refactor into a 3.x application. So this
effectively means that we are going to either need to fast track this effort
which is likely not going to happen, or make the attempt to migrate to 3.x
with an application the size of an elephant.

Definitely not going to be fun!

~~~
phillmv
Hello!

I have performed two rails 2 upgrades. Both cases they were smallish apps, but
they took 3-5 days to feel comfortable with everything that's happened.

If this is an app that is still being actively developed, I highly recommend
you fast track it.

[If not, look up the community-managed security back port branch and switch to
that asap]

Basically, the problem stems from bit-rot and alas such is the nature of our
industry. In a nutshell, the longer you wait the harder it is to find quality
docs on what's changed and how to fix it. A lot of links are now gone.

The main challenge comes from: the change in the router, the changes in the
view api (everything is escaped by default, and you will find a ton of string
concats in your helpers that will now spit out garbage), migrating over to the
asset pipeline (which I personally found confounding for a long time until I
got the hang of it), migrating over to Arel queries and updating all of your
plugins - many of which will stop working in quirky ways. You may also
experience pain with updating your test suite.

So, there's a lot of _yak shaving_ but you don't actually have to refactor
your app much. Your controllers will remain basically untouched and so will
your models modulo named scopes and certain now preferred validation patterns.
Most of the pain is view-focussed.

Oh, and the attribute protection but that pain is a good pain, you really need
to whitelist your attributes. IF YOU ARE READING THIS MAKE SURE YOUR MODELS
HAVE AN `attr_accessible` THAT DOES NOT HAVE ANY ATTRIBUTE THAT ENDS IN `_id`.

There's a phenomenal plugin that will help a lot -
[https://github.com/rails/rails_upgrade](https://github.com/rails/rails_upgrade)
\- but it's not going to catch _everything_.

~~~
johnbellone
The problem that we run into is that most people haven't upgraded a 2.3
application that is our size. We're already aware of the community-managed
backports, but ideally we will just be able to fast track moving towards 3.2
soon.

We have actually backported sprockets/asset pipeline quite awhile back and
have been using it without any major problems.

Definitely aware of the benefits its just very hard to do something at the
scale that we're at :). Earlier this year our REE -> 1.9.3 upgrade took about
a month and a half. For the past year we've been moving to separate, smaller
applications and then breaking those into mountable engines within each
application.

Appreciate the feedback though and the links!

~~~
alxndr
Some folks from New Relic gave a talk at RubyConf this year about upgrading
their old-for-Rails project from 2 to 3, I found it pretty informative
[http://www.confreaks.com/videos/2425-railsconf2013-changing-...](http://www.confreaks.com/videos/2425-railsconf2013-changing-
the-wheels-on-the-bus-at-80-mph-upgrading-to-rails-3-on-a)

------
usethis
This is an awesome achievement.

There are so many improvements to this version that are not immediately
visible, but which are maturing Rails in tremendous ways. I think it compares
with the release of Mac OS X Snow Leopard (10.6). Especially in the perception
on different types of users (experts to consumers).

On a different note, moving from 3.2 can best be done one gem at the time. For
instance, implement strong parameters and you're one step closer to Rails 4.
[https://github.com/rails/strong_parameters](https://github.com/rails/strong_parameters)

------
danso
So...what have people's experience been in trying to have fat-client-like
speed with TurboLinks? Not necessarily with Rails 4.0, but in general? I
imagine for some Rails users, the decision is not just whether to go from
2.x/3.x to 4, but whether to go to Sinatra + Backbone/Angular/Ember/etc

~~~
k1w1
The speed improvement from turbolinks can be quite significant. I have an
application that was purpose built for pjax and later converted to turbolinks.
Page loads are noticeably faster than without turbolinks, and are on the same
order as a fat-client application.

The beautiful part is that while writing most code in pure Rails you don't
need to think about turbolinks at all - it just comes for free.

BTW, turbolinks is a bit improvement over pjax. It is much simpler (since the
whole page is loaded), discouraging some of the complexity that you might be
tempted to introduce by pjaxing different parts of the page.

Converting an existing app to turbolinks will take some work, especially with
how JS is handled. The key is to run your JS on the turbolinks "page:change"
callback and then call the same callback on the initial page load:

    
    
        $ ->
          # Simulate turbolinks page change on document ready.
          $(document).trigger "page:change"

~~~
cheald
Does it still break horribly and double-request everything if you have things
like <link rel="canonical"> in your website?

~~~
chc
I don't know when it was doing that, but the current version of Turbolinks
only seems to affect the Asset Pipeline. It doesn't do anything to random link
tags on your page. I specifically checked a page with rel="canonical" and
Turbolinks only made one request.

~~~
cheald
Last I looked at it, Turbolinks parsed the <head> section of the incoming
request to see if any assets (which was basically...count the script/link
nodes) changed. If they did, it went ahead and redirected to the requested
URL, since it couldn't be sure that assets hadn't changed.

This meant that anything page-specific in your <head> caused Turbolinks to
double the work your app had do to, and provided no positive benefit at all.

I'll check and see how it's behaving now.

Edit: Looks like concerned assets are now tagged with a data attribute. Glad
that's in there now.

------
angersock
After looking over the changelog and doing a little research: it seems like
this Turbolinks thing is now default-on for Rails 4.

This screws up the normal .ready() stuff, right? Has this bitten anyone yet?

~~~
steveklabnik
Yes, Turbolinks is included by default, but it's really easy to not use if you
don't want to: [http://blog.steveklabnik.com/posts/2013-06-25-removing-
turbo...](http://blog.steveklabnik.com/posts/2013-06-25-removing-turbolinks-
from-rails-4)

~~~
angersock
Right, this is good--but are fears of mysteriously-breaking javascript
depending on the ready event unfounded?

~~~
breckenedge
If you're using jquery, then there is already a gem for that: jquery-
turbolinks
([https://github.com/kossnocorp/jquery.turbolinks](https://github.com/kossnocorp/jquery.turbolinks))

~~~
mieko
jquery-turbolinks as a drop-in fix worked great for my application. The only
tweaks my own code required at that point were resources I assumed would die
and be recreated on the next page load, like doubling up setInterval handles
in domready.

------
bti
Maybe a little off topic... I just started a small project using Angular and
Rails, learning both from scratch as I go. I am using Rails as a purely JSON
server and handling all the templates in Angular and doing requests over
$http. Is it worth using Angular just for the UI niceness and using more of
Rails? I need things like authentication and sessions but at its roots it is a
single page app. Would any of this new Rails 4 turbolinks stuff help?

~~~
steveklabnik
The Rails-API project is here to help! [http://github.com/rails-api/rails-
api](http://github.com/rails-api/rails-api)

I don't personally know of anyone using Angular + Turbolinks, so I can't
answer that.

~~~
playing_colours
Thanks, I'm building Angular.js app and adopting Rails 4 for api backend, Will
Rails-API be updated for Rails 4 ?

~~~
steveklabnik
It should work today. If it does not, it's a bug.

By the way, ActiveModel::Serializers is part of the Rails API project[1], and
we'd love some thoughts on how to make it work well with Angular.

1: [https://github.com/rails-
api/active_model_serializers](https://github.com/rails-
api/active_model_serializers)

~~~
janus
The only issue that's been biting me when using ActiveModel::Serializers and
AngularJS is that we must manually return the json with the root: false option
set, otherwise the AngularJS $resource provider doesn't work correctly.

~~~
lentil
If it helps you can make that the default for all your serializers, by doing
something like this in an initializer:

    
    
        ActiveSupport.on_load(:active_model_serializers) do
          ActiveModel::ArraySerializer.root = false
          ActiveModel::Serializer.root = false
        end

------
rubiquity
Darn. I bought Crafting Rails Applications in paperback three months ago :(

On another note, I've been using Rails4 beta and RCs at home for the past
couple months and it has been a joy. At work I've also been working on a Rails
3.2 app and incorporating routing_concerns and strong_parameter gems. I think
upgrading from Rails 3 to 4 apps won't be as drastic as upgrading from Rails
2.x to 3 apps was (curse you asset pipeline!)

~~~
hackerboos
There's a new edition of that out November:

[http://pragprog.com/book/jvrails2/crafting-
rails-4-applicati...](http://pragprog.com/book/jvrails2/crafting-
rails-4-applications)

------
jazearbrooks
I've been looking forward to this for a long time. Congrats to the Rails team!

Now I just need a good book on Rails 4.0 or for Michael Hartl to update the
Rails tutorial.

~~~
heidar
He has already updated it, not sure if it is the final version yet:
[http://ruby.railstutorial.org/ruby-on-rails-tutorial-
book?ve...](http://ruby.railstutorial.org/ruby-on-rails-tutorial-
book?version=4.0)

~~~
jazearbrooks
Yea I've seen that but I don't want to start until I know it accounts for the
final version of 4.0. When he first released it for 4.0 beta, there were major
inconsistencies between that and one of the release candidates.

~~~
sigzero
Obie says above it has been "fully updated".

------
VeejayRampay
Thanks to all the committers and releasers involved. The countdown to Rails 5
has begun :D

~~~
johnbellone
4.1 :)

------
elsurudo
Just wanted to point out this great resource for upgrading:
[http://railsdiff.org](http://railsdiff.org)

It diffs the initial 'rails new' project between any two versions.

------
ndcrandall
I have been using 4.0.0.rc1 for about a month now and have enjoyed the
process. There have been a lot of great updates since the previous versions.

I will caution all to be aware of the turbolinks included by default. I spent
a while scratching my head why a setTimeout function worked every so often. I
had no prior experience with turbolinks or the discussion thereof, though I
believe it's a great feature.

------
oelmekki
The russian doll cache looks awesome, but I'm a bit worried about this bit in
dhh's explanatory article :

> The beauty of that system is that you just don’t care. Memcached will
> automatically evict the oldest keys first when it runs out of space

Well, I do care : I use redis as cache backend. I guess it will not be as
simple as that.

~~~
oelmekki
To answer myself : it's possible to use a maxmemory-policy=volatile-ttl
directive to tell redis to remove older keys. Problem is, it's not reliable at
all : it will actually take a bunch of unpredictable keys and remove the
oldest in the set.

[http://stackoverflow.com/questions/9010789/configuring-
redis...](http://stackoverflow.com/questions/9010789/configuring-redis-to-
consistently-evict-older-data-first)

I currently empty redis cache on each deployment, so that's not really a
problem, but it will be when I use a less naive cache invalidation on code
update (and I'm pretty sure some of you are).

So, we'll probably have to take a look in rails cache internal and force
sweeping when computing a new key (this will not be a major problem on redis,
since it supports wildcards in key names).

------
vysakh0
Is it only me or anyone else facing issue installing the gem? Getting this
error

ERROR: While executing gem ... (Gem::RemoteFetcher::UnknownHostError) no such
name
([https://rubygems.org/gems/actionpack-4.0.0.gem](https://rubygems.org/gems/actionpack-4.0.0.gem))

Edit: Now it is working :)

------
zachgersh
Has anyone actually had a go with the threading as of yet? I'd love to
actually see some performance #s!

~~~
pimeys
We're running some of our applications with threaded 3.2 and Passenger. Not
the easiest job to convert your app, but in some cases really worth the
trouble.

------
Legion
Trying to download the latest Agile Web Dev w/Rails from PragProg and just get
the error, "File is not ready yet". On two separate accounts.

Also, this post describes today's book release as the "final" version, but the
PragProg changelog calls it Beta 4.0.

------
throwaway420
Congrats to the team on a great release.

I'm curious how does this affect the rails-api project?

~~~
steveklabnik
It should work today, as we've been tracking edge Rails for a while. If it
does not, that's a bug. Please file an issue if you find anything.

------
revskill
A question: Could someone tell me which types of application does Rails 4.0
solve, but the older versions couldn't ? In general, which types of
application could not be solved by Rails 4 ? Thank you.

~~~
pkroll
I'm basing this on what I've read, and my experience with Rails 3, so take it
with a grain of salt. The type of application you couldn't do in the older
one? Easy single-page apps. Of course you COULD do it, writing your own
JavaScript or CoffeeScript. But Turbolinks and the Russian Doll caching give
Rails 4 a way to get much of the speed of those custom-written apps and yet
stay in Ruby/Rails.

I don't know of any type of application that Rails 4 CAN'T do, but it's still
Rails and Ruby, so anything computationally intense would probably be better
served (ha!) by a Java (or Go, or Scala, or...) framework. The further you get
from a CRUD app, the less useful the Rails framework becomes.

------
ciniglio
Has anyone read any of the books mentioned in the link (or Rails 4 in Action)?
Any recommendations for someone that is intermediate in Rails 3, but would
like to become more advanced?

~~~
owenjones
The Rails 3/4 Way by Obie Fernandez was really helpful to me. It's more of a
cookbook or reference guide that really deep dives into each aspect of Rails.

Definitely not a good choice for 1st Rails book though.

Another recommendation for it below from jherdman & jazearbrooks.

~~~
hipsters_unite
The Rails 3 Way was the book that cracked it for me. Hartl's tutorial is a
great start, but Obie's was the book that actually hit the 'why' on the head.

------
ahawkins
Is there anything else Rails can do? I can only think of a unified queuing API
(which was scheduled by dropped from this release). Has Rails reached feature
completeness?

~~~
VeejayRampay
Try doing WebSockets in a Rails app for example. Rails was born in an age of
request/response and sometimes it shows. And I say that as a Rails enthusiast.

~~~
ahawkins
Ya. I'd like to see better support for that. The problem is the
ruby/javascript bridge.

------
dfischer
Great work guys. It shows.

