Rails 3.2 RC1: Faster dev mode & routing, explain queries, tagged logger, store

Posted by David December 20, 2011 @ 12:46 AM

Once you’ve boarded the Rails train, you just know that every stop along the way is going to be a good time. This release candidate is no different and we’ve packed it with loving goodies without making upgrading a hassle.

Faster dev mode & routing

The most noticeable new feature is that development mode got a ton and a half faster. Inspired by Active Reload, we now only reload classes from files you’ve actually changed. The difference is dramatic on a larger application.

Route recognition also got a bunch faster thanks to the new Journey engine and we made linking much faster as well (especially apparent when you’re having 100+ links on a single page).

Explain queries

We’ve added a quick and easy way to explain quieries generated by ARel. In the console, you can run something like puts Person.active.limit(5).explain and you’ll get the query ARel produces explained (so you can easily see whether its using the right indexes). There’s even a default threshold in development mode where if a query takes more than half a second to run, it’s automatically explained inline—how about that!

Tagged logger

When you’re running a multi-user, multi-account application, it’s a great help to be able to filter the log by who did what. Enter the TaggedLogging wrapper. It works like this:

Logger = ActiveSupport::TaggedLogging.new(Logger.new(STDOUT))
Logger.tagged("BCX") { Logger.info "Stuff" } # Logs "[BCX] Stuff" 
Logger.tagged("BCX") do
  Logger.tagged("Jason") do
    Logger.info "Stuff" # Logs "\[BCX\] \[Jason\] Stuff" 
  end
end

Active Record Store

Key/value stores are great, but it’s not always you want to go the whole honking way just for a little variable-key action. Enter the Active Record Store:

class User < ActiveRecord::Base
  store :settings, accessors: [ :color, :homepage ]
end
u = User.new(color: 'black', homepage: '37signals.com')
u.color                          # Accessor stored attribute
u.settings[:country] = 'Denmark' # Any attribute, even if not specified with an accessor

These are just a few of the highlights. The full release notes detail every loving change.

Given that this is a release candidate, we’re ever so eager to hear your feedback. We hope it’ll be a quick RC phase, but please do spoil that plan by reporting bugs.

As always, you install a release candidate by doing gem install rails --pre.

Posted in Releases | 25 comments

Comments

  1. judearasu on 20 Dec 00:53:

    Great to have explain queries :)

  2. yonafin on 20 Dec 00:54:

    Faster dev!

  3. The Dude on 20 Dec 01:09:

    Does the query explain also work for PostgreSQL, SQLite, Oracle and/or SQL Server? I’m fairly new to Postgres, and I know it’s available in MySQL since I’ve used it there before, but don’t know about the others.

  4. damncabbage on 20 Dec 01:09:

    These look great, but I’m a little worried about this ‘store’. It reminds me far too much of the Wordpress settings table; I expect there will be much swearing the first time someone typos :country.

  5. noice on 20 Dec 01:18:

    Funny thing is that I initially though when I started with Rails that it already reloaded only files that has changed… it took so many versions for this to get true. At least i can throw away railsdevboost gem now. Thanks for the excellent work though, great release!

  6. Kiwi on 20 Dec 01:31:

    I get this:

    DEPRECATION WARNING: ActionDispatch::ShowExceptions.rescue_responses is deprecated. Please configure your exceptions using a railtie or in your application config instead. (called from <top> at …config/environment.rb:5)

  7. wangyaodi@gmail.com on 20 Dec 01:42:

    Awesome Updates!

  8. Leandro Maioral on 20 Dec 01:47:

    I keep geting this (i’m using HAML):

    instance of IO needed

    Extracted source (around line #17):

    14: = favicon_link_tag asset_path(‘apple-touch-icon.png’), rel: ‘apple-touch-icon’, type: ‘image/png’ 15: 16: /[if lt IE 9] 17: = javascript_include_tag “html5” 18: = javascript_include_tag “chrome_frame” 19: 20: = stylesheet_link_tag “application”

  9. Andrew de Andrade on 20 Dec 02:20:

    Seeing as the javascript is becoming a full-fledged client, wouldn’t it be prudent to start thinking about how to handle all JS code separate from ruby.

    Right now, a client-side javascript app is highly coupled with the back-end that serves it. The move to Sprockets increased this coupling. While I like Sprockets for helping my team handle Sass files easily, it does make javascript more complex because it is now competing in areas where convention has yet to be defined. Sass will always be pretty portable because it is by and large very orthogonal and there aren’t lots of interactions.

    With Javascript, there are more and more points of contact between Rails and Javascript code. IMHO ideally there should be two points of contact: (1) RESTful API interface, and (2) Publishing of assets.

    Javascript is no longer merely as asset. For many developers doing advanced stuff, this asset class is the app.

    Right now all the activities associated with publishing are handled by Sprockets: testing, concatenation, minification, linting, etc.. This makes it hard to separate the client from the server. It would be nice to have javascript handle javascript. It should be easier to coordinate the use of JSLint, Require.js, Backbone.js, Jasmine, etc. without being dependent on Ruby and Rails as a mediator.

    Handing off all javascript responsibilities to javascript should be easier than it is.

  10. God on 20 Dec 02:45:

    Inspired by Active Reload, we now only reload classes from files you’ve actually changed.

    What if I change a module that is included by another class? What would happen to that class? Would it see the changes in the module?

    You also have a typo here:

    quick and easy way to explain ->quieries<-

  11. rtdp on 20 Dec 06:57:

    +1 to faster dev !!

  12. Dean on 20 Dec 08:05:

    Got error:

    gem install rails—pre ERROR: While executing gem … (NoMethodError) undefined method `call’ for nil:NilClass

  13. Xavier Noria on 20 Dec 10:22:

    @God reloading still wipes all autoloaded constants. But it only does so if some of their files has changed, rather than doing it for every request.

  14. Ollie on 20 Dec 12:08:

    Awesome, thanks again. :)

  15. Ernie on 20 Dec 12:14:

    Still hoping to get Valium (values_of) integrated instead of pluck, but I’m guessing it’s too late since the RC has hit: https://github.com/rails/rails/pull/3871

    Is the ActiveRecord store basically attr_bucket looks like it from the description.

    https://github.com/ernie/attr_bucket

  16. nm on 20 Dec 14:35:

    @Andrew de Andrade:

    I think Cinco is supposed to address some of your concerns. Hopefully 37S will release or provide an update on the project.

  17. Hamid on 20 Dec 14:55:

    That’s cool, Fantastic.

  18. cbmeeks@gmail.com on 20 Dec 16:19:

    Screw this. I hate being so efficient in Rails. I’m going back to Struts 1 and Java. I like my crud forms taking 3 days thank you very much.

  19. Aaron on 20 Dec 18:36:

    sass integration seems to be horribly broken in this release right now. Curse you asset pipeline!!!

  20. Happy Active Reload user on 20 Dec 20:53:

    If you (like me) found the new Active Reload extlemely useful and time/costs saving feature, then we can now say THANK YOU to the Author of this gem here: http://pledgie.com/campaigns/15547

    Once again: thank you!

  21. Andrew de Andrade on 20 Dec 21:09:

    @nm,

    Stitch definitely looks like a better approach than the sprockets directives. I think it would also be much easier to replace stitch with require.js if you want AMD style script loading.

    What I’m not happy about is Eco in the Cinco framework.

    The whole coffeescript by default is starting to result in a schism in open source libraries. You no longer have people contributing to the best library of libraries for a certain task. Instead you have people contributing to the best library or libraries written in either CS or JS. CS is resulting in a lot of duplicated effort solely because of syntax.

    A community splitting in two over syntax is a huge waste. The personal gains a developer gains from using CS is now causing a loss for the larger JS community because of duplicated efforts.

    Duplicated efforts isn’t always bad when there is diversity in the solutions. But duplication over syntax is a prime example of a group being its own worst enemy.

  22. Roamlog Lee on 21 Dec 01:20:

    @Leandro Maioral

    maybe you can run rake assets:precompile to fix it

  23. Eric Berry on 22 Dec 14:52:

    There are great additions! Kudos!

  24. John Brinda on 22 Dec 16:25:

    @Leandro Maioral & Roamlog Lee

    Had same problem upgrading an old app, “rake assets:precompile” did fix it.

    @rails developers

    A more helpful error message here would be nice. Regardless, kudos on 3.2, dev is significantly faster, wow!

  25. Zachery on 27 Dec 19:46:

    @Kiwi

    I get the same deprecation error for rescue_responses but cant seem to find where its coming from. this happens when using Spork but not when calling rspec directly. Though rescue_responses does not exist anywhere in my code or in spork’s code (or watchr, OR rspec OR rspec-rails.) And this is just a deprecation warning not an error causing a full backtrace. So im at a loss as to whats causing this.