This Week In Rails: Doctrine, Weak ETags, Cabled Postgres and more!

Hey passengers!

Have your luggage ready and get those ticket stubs out, a new issue is just about to roll in to the station. Godfrey and Kasper are co-conducting this beast of steel — eh, newsletter with Rails news, we mean.

Hop aboard before we roll off, and start choo-chooing toward…

Hey, does that sign say “Tracks End Here”?

Fresh off the tracks, a new Rails site!

Ahead of the coming major release of Rails, we got a new website and logo and… doctrine?

Yes! See, Rails has been going strong for over 10 years, the Rails Doctrine just captures that magic and spells it out. Thus Rails is ready to roll on for the next decade. The blog post dishes on the new design’s backstory.

P.S. The Rails core team got some awesome new pictures too!

This weeks Rails Contributors

This week 41 people contributed managed to rivet themselves away from the shiny new pixels above and buckle down some contributions. Kudos to you folks 😁

New Stuff

Action Cable: Postgres pubsub can sub for Redis

Action Cable uses Redis to handle publishing and subscribing, but this week Postgres became a proper pubsub’er and is swappable with Redis.

SQL expressions as a column’s default value

With this pull request, you will be able to use a SQL expression (such as a SQL function) as the default value for any column type!


Weaker ETags makes HTTP caches stronger

HTTP ETags help cut bandwidth by sending along a tag that the server could use to validate the cached content.

Rails supports it out-of-the-box but issues “strong” ETags, which has stronger cachability implications than Rails can guarantee.

Not anymore! In Rails 5, Rails now correctly issue “weak” ETags — matching Rack::ETag’s behavior.


Removed Action Cable’s celluloid dependency

Action Cable’s dependency on the celluloid gem has been removed by using the thread pool from concurrent-ruby (which Rails already uses). While temporarily reverted it was reintroduced this week.

Better configuration documentation for Action Cable

Now rejiggered: the Action Cable documentation on how to configure the library has been clarified and better highlights how useful some methods are.

Wrapping Up

That’s all for This week in Rails. As always, there are plenty of things we’re not able to cover here, so take a peek at the changes yourself.

Until next time!

New Rails identity

It’s been 10 years since we last updated the Rails identity, so with Rails 5 just around the corner, we thought it was finally time for a fresh look for a new day. This is it! We have a brand new logo, a brand new site design, and lots of lovely new illustrations.

We can thank Basecamp designer Jamie Dihiansan for the awesome new look. The brief was that Rails shouldn’t feel slick. It should be warm, approachable, and welcoming. Rails is in a different place from where it was in 2004. We aren’t courting cutting-edge early adopters, so we can lay off the gradients. Rails is now for everyone and our site should reflect that.

The Rails Doctrine

In concert with the new look, I wrote the eight major tenets of The Rails Doctrine. It’s still a bit of a work in progress, but please do give it a read if you want to understand deeper the values and practices that underpin us as a framework and a community.

A new video is coming

I was going to record a new video for the homepage, but since we’re just on the cusp on some changes to Rails 5 that’ll change things a bit, I’m holding off until beta2 (which should be out shortly). In the mean time, you can enjoy the introduction to Action Cable. But rest assured that it’ll soon be replaced by a new, proper introduction.

Hope you all enjoy the new look. Now let’s ship Rails 5!

This week in Rails: Happy New Year!

Happy New Year! Welcome to the first 2016 issue of This week in Rails.

I’m Andy, and before diving in to contributions from this week, let’s briefly recap some stats from 2015. Our 12 editors released 50 issues summarizing over 6500 commits to Rails! Each issue is now being sent to over 4300 subscribers.

What a great year! To celebrate, sweep up some confetti laying around from last weekend, toss it in the air, and sing some bars of Auld Lang Syne.

This Week’s Rails Contributors

79 people contributed to Rails since the last issue on December 18, 2015! Check out the list of issues if you’d like to help out as well.

RailsConf 2016 CFP deadline

Interested in speaking at RailsConf 2016 in Kansas City? Call for proposals closes January 15th, 2016, 11:59pm CST! You’ve got 1 week!

New Stuff

Security: Per-form CSRF tokens

Changes brought upstream from GitHub, related to Content Security Policy (CSP) and securing forms. Check out the links in the PR to learn more.

Default new apps to tag logs with request_id

The :request_id log tag ensures that each request is tagged with a unique identifier.

Short-hand methods for types in MySQL

This change adds short-hand methods like tinyblob and mediumblob for text and blob types when using MySQL.


Don’t output to STDOUT twice

Stops printing messages twice with rails console or rails server and a logger set to output to STDOUT.


Replace{} with{}

Small performance improvement supported with a benchmark. Check out the results.

Wrapping Up

That’s all for This week in Rails. As always, there are many more changes than we have room to cover here, but feel free to check them out yourself.

Until next time!

This week in Rails: Rails 5 - The Beta Awakens

I hear you’re looking for a pilot. Name’s Todd Solo, captain of This Week in Rails. She may not look like much, but this bucket of bolts did the Kessel Run in less than twelve parsecs. She’s more than capable of smuggling all of the latest Rails intelligence to you.

I’ve got a very Special Edition™ for you this week - we’re celebrating the release of the very first beta of Rails 5! We’re going to be covering all of the big additions made since the release of Rails 4.2 in this issue. Don’t worry - no Bothans died to bring you this information.

This Release’s Contributors

We had 790 scruffy-looking nerf herders contribute to this release. That’s over 7000 commits in a little over a year! Give all of these folks a big round of applause!

Rails 5 Only Supports Ruby 2.2.2+

This is important - Rails 5 will only support versions of Ruby greater than 2.2.2. Ruby 2.2 introduces a number of new features and performance enhancements that the Rails team wants to capitalize on. You can read more about Ruby 2.2 in the release announcement.

New Stuff

Action Cable

In case you haven’t heard, Rails 5 is bringing WebSocket support along with it! Action Cable is a completely integrated solution for building WebSocket apps in Rails. Give it a spin!

Rails API

Rails 5 introduces support for API-only apps. Based on the wonderful work done by the Rails API project, you can now generate apps that strip out parts of Rails not needed for pure backends.

New Command Router

Why do you start a console with rails console, but run migrations with rake db:migrate? That doesn’t make any sense. Starting in Rails 5, many of these old rake commands can be run with rails instead.

Attributes API

Your models are getting a new attribute class method in Rails 5, allowing you to easily define a relationship between the model and a non-Active Record type. No more misusing serialize!


Just like ApplicationController, we’re getting an ApplicationRecord model superclass in Rails 5. Now you don’t have to monkeypatch ActiveRecord::Base to add functionality!


A long requested feature, ActiveRecord::Relation is finally getting the #or method we’ve all wanted.

Wrapping Up

That’s all for This week in Rails. As always, there are plenty of things we’re not able to cover here, so I highly recommend you take a peek at the release announcement and CHANGELOGs.

We’ll be back to our regularly scheduled program next week.

Until next time - may the Force be with you!

Rails 5.0.0.beta1: Action Cable, API mode, Rails command

Rails 5.0! Can you believe it? We only just celebrated the tenth anniversary of Rails 1.0 a few days ago. Time flies when you’re having fun with good friends, and we’ve never had more fun or better friends in the Rails community, so no wonder it’s going swoosh! Now this is just the first beta release, but Rails 5.0.0.beta1 is already running Basecamp 3 in production.

Action Cable

The big new thing in Rails 5.0 is a brand-new framework for handling WebSockets called Action Cable. It’s a completely integrated solution that includes an EventMachine-powered connection loop, a thread-backed channels layer for server-side processing, and a JavaScript layer for client-side interaction. It’s incredibly easy to use, and makes designing live features like chat, notifications, and presence so much easier. It’s what’s powering all those features of Basecamp 3, if you want to see it in action.

What’s really lovely about Action Cable is that you get access to your entire Active Record and PORO domain model in your WebSockets work. We even added a brand-new ActionController::Renderer system that makes it trivial to render your templates outside of controllers, when you want to reuse server-side templates for WebSocket responses.

In development, Action Cable runs in-process with the rest of your app. To do this, we’ve switched the default development server from Webrick to Puma. In production, you may well want to run Action Cable servers in their own processes. That’s how we run it at Basecamp at scale.

Special thanks to Pratik Naik and Javan Makhmali for their formative work.

API mode

Rails is not only a great choice when you want to build a full-stack application that uses server-side rendering of HTML templates, but also a great companion for the new crop of client-side JavaScript or native applications that just needs the backend to speak JSON. We’ve made this even clearer now with the new –api mode. If you create a new Rails application using rails new backend --api, you’ll get a slimmed down skeleton and configuration that assumes you’ll be working with JSON, not HTML.

There’s still more work to be done on this feature, but we’re off to a great start. By default, API mode just relies on #to_json calls on model classes. But you can either use Jbuilder, Active Model Serializers, or look at the new JSONAPI::Resources project for a more advanced solution.

Thanks in particular to Santiago Pastorino and Jorge Bejar for making this happen.

One Rails command to rule them all

Why are some commands living in bin/rails and some commands living in bin/rake? That’s a common question, especially for beginners, and we never had a good answer (just lots of technical excuses). So now we’ve committed to making bin/rails the one master command to rule them all. All your rake commands are available through here as a gateway, but we’ll eventually port many of them over. So your fingers will now have to get used to bin/rails db:migrate instead of bin/rake db:migrate. That should only take a few months!

Kasper Timm Hansen has been herding this project.

A few other highlights

  • New Attributes API by Sean Griffin.
  • The test runner now reports failures inline, so you don’t have to complete the suite to see what went wrong.
  • ApplicationRecord has been born as a default parent class of all models created by the generators.
  • ActiveRecord::Relation#in_batches makes it much easier to deal with record work in batches at a time to lessen memory overloads.
  • Post.where(‘id = 1’).or(Post.where(‘id = 2’)) gives you exactly what you’d think!
  • No more accidentally halting Active Record callbacks because the last statement is false. Now you throw(:abort) explicitly!

You should really checkout the CHANGELOGs, though. There’s just so much new and good stuff available in all the frameworks:

Claudio did a nice little slide deck walking through some of his favorite improvements (and removals!).

Note too that we’re cooking Turbolinks 5 – the one with native iOS and Android wrapper implementations! – for concurrent release with Rails 5. You can follow along on basecamp/turbolinks/v5.

Maintenance consequences

As per our maintenance policy, the release of Rails 5.0 will mean that bug fixes will only apply to 5.0.x, regular security issues to 5.0.x and 4.2.x, and severe security issues also to 5.0.x and 4.2.x (but when 5.1 drops, to 5.1.x, 5.0.x, and 4.2.x). This means 4.1.x and below will essentially be unsupported! Ruby 2.2.2+ is now also the only supported version of Ruby for Rails.

Please help us make Rails 5.0 solid!

We rely on the feedback from everyone in the community to flush out bugs and upgrade issues ahead of a big release like this. So please give Rails 5.0 a try on your app, and if you’re starting a new app today, you should probably use the beta1 for that, if you’re just the least bit savvy with Rails.

Issues can be recorded on the Github issues tracker.

Already, 789 people have contributed to this new release of Rails. Please do become one of them!

Your dynamic release manager duo for Rails 5.0 is Eileen M. Uchitelle and Sean Griffin. And the undisputed PR merge champ is Rafael França!

This week in Rails: GZipped Asset, API error responses and more!

Hello everyone! 🌨

This is Vipul, bringing you the latest from Rails.

P.S: Here’s something for all those at RubyKaigi 🍣. Enjoy!

This Week’s Rails Contributors

This week 26 fabulous people contributed to Rails, including 6 first-time contributors! Check out the list of issues if you’d like to help out as well.

Sprockets: Reintroduce gzip file generation

GZip file generation was taken out last year from sprockets. This change re-introduces compressed file generation and parallel file writing, which is useful for web servers that don’t support gzipping static assets. This is pretty useful if you are on a service like Heroku.

New Stuff

Introduce after_{create,update,delete}_commit callbacks

New shortcuts were added to after_commit .. on: :action.

For example, after_commit :add_to_index_later, on: :create can now be written as after_create_commit :add_to_index_later.


Rails API: Ability to return error responses in json format in development

Previously error pages are always being delivered in html pages in development mode, which is not handy when you would like to view json responses. This change adds support for viewing errors in json format. It also makes sure that when requesting resources like post/1.json, when error occurs, it returns json response based on json format in url, unlike previously used html format.

Changed the protect_from_forgery prepend default to false

protect_from_forgery will now be inserted into the callback chain at the point it is called in the application. This is useful for cases where you want to protect_from_forgery after you perform required authentication callbacks or other callbacks that are required to run after forgery protection.

If needed, you can use protect_from_forgery prepend: true to always run protect_from_forgery before others.

request_forgery_protection initializer is removed from Rails API

Usually in Rails API, you would not use protect_from_forgery, by default. The initializer to add this option- request_forgery_protection is now removed if you are creating an API.


Subscribing to notifications while inside the instrumented section.

Previously if we tried to do

ActiveSupport::Notifications.instrument('foo') do
  ActiveSupport::Notifications.subscribe('foo') {}

it would create an error, because for the subscribe inside block, the dynamic subscription does not yet exist. This change make sure that subscriptions inside instrumentation get notified as well.

Add redirection path in the error message of assert_response if response is :redirect

Previously, if assert_response was checking for any non-redirect response like :success and actual response was a :redirect then, the error message displayed was like - Expected response to be a <success>. This change, now shows the redirected path in error response as - Expected response to be a <success>, but was a redirect to <>

Wrapping Up

That’s all for This week in Rails. As always, there are many more changes than we have room to cover here, but feel free to check them out yourself.

Until next time!

This week in Rails: Rails command infrastructure and more!

Hello everyone!

This is Marcel, bringing you the latest news in Rails.

This Week’s Rails Contributors

This week 28 fabulous people contributed to Rails. Check out the list of issues if you’d like to see your name up there.

New Stuff

Rails Command Infrastructure

The infrastructure needed to support the movement of rake tasks to the rails command is now in place. This paves the way to make it easier to learn commands for persons new to Rails.


Allow use of minitest-rails gem with test runner

An explicit global namespace to Rails::TestUnitReporter has been added to resolve a namespace conflict between minitest-rails and Rails test runner.


Initialized STI models are now casted to the default type

If a database default was specified for the type column used in Single Table Inheritance (STI), it did not cast new instances to default type on initialize. This is now fixed.

Replace ActionMailer::Base.respond_to? with respond_to_missing?

This simple refactor utilizes the respond_to_missing? hook introduced in Ruby 1.9. This prevents the usage of the method method from raising a NameError.

Clarify connection pool error message

The previously error message whenever all connections in the pool were used up, did not mention that.

Wrapping Up

That’s all for This week in Rails. As always, there are many more changes than we have room to cover here, but feel free to check them out yourself.

Until next time!

This week in Rails: Don't Miss Our Black Friday and Cyber Monday Deals!

Hello everyone!

This is Godfrey, bringing you the latest news deals in Rails. Have you been holding out on getting the latest copy of Rails? Don’t wait any longer as we are having our biggest sale of the year this weekend. Check out these unbelievable deals before they are gone!

🆓 RailsConf Tickets Giveaway

Limited Time Offer! Enter the RailsConf Tickets Giveaway (a.k.a. the Call For Proposals) by submitting a talk proposal! If your talk is selected, you will win a FREE admission to the conference!

Terms and conditions apply, see website for details.

🆓 Lifetime Rails Contributor Membership

As Seen On The Interwebs! Start collecting points like these 25 individuals with our award-winning rewards program. To apply for your FREE membership, simply submit a pull request to Rails. Membership never expires!

New Stuff

🆓 PostgreSQL Geometric Types Support

In-Store Only! Get FREE support for PostgreSQL data types (such as line, path and polygon) in schema.rb when you upgrade to Rails 5.

🆓 Certificate of Origin

Bonus Upgrade Offer! Rails 5 apps will be equipped with a FREE Origin header check if one is present in the request. When upgrading, existing apps will be given an option to enable the security feature at no additional cost.


🆓 Source Code Extraction

NOT A Pricing Error! If something went wrong in an AJAX request, Rails will now throw in the extracted source code in plaintext for FREE, making things easier to read in your browser’s console.

🆓 Dead Code Removal

Everything Must Go! As part of our clearance, a piece of dead code was discovered and promptly set FREE. No wonder everyone is so excited!


🆓 Race Condition Protection

While Supplies Last! When the Evented File-System Monitoring project landed on master, a contributor pointed out a potential race condition. After ( a few attempts, we have finally arrived at a solution to FREE us from the danger!


🆓 byebug Upgrade Program

Manufacturer Rebate! In the last issue, we recommended byebug 7.0. Turns out the latest version is actually 8.2.1 (as of this week), which addressed some issue with the 7.0 release.

To compansate you for the trouble, we decided to offer a FREE byebug upgrade program for our readers. Simply change your Gemfile entry accordingly and run bundle install, and our agents will make sure the library is upgraded.

Wrapping Up

That’s all for This week in Rails. As always, there are many more changes deals than we have room to cover here, but feel free to check them out yourself.

Until next time!

This week in Rails: RailsConf 2016, frozen Hash keys, faster byebug and more!

Hi everyone! This is Godfrey bringing you the latest news from Rails.

RailsConf 2016

The RailsConf 2016 website is up! This year, we will be gathering in Kansas City from May 4 to May 6. If you would like to submit a talk, the call for proposals (CFP) is open from now until Jan 15!

This Week’s Rails Contributors

This week we have seen commits from 29 different contributors in the Rails repository, including 6 new faces!


Frozen FK Names For Association

When you use a non-frozen (i.e. mutable) string as a Hash key, Ruby would have to duplicate and freeze it in order to guarantee a stable hash key.

This is usually fine, but when that string is used to build many different hashes, the work adds up. Fortunately, we can simply freeze it upfront to avoid the repeated work.

Faster byebug

byebug 7.0 has recently been released with some major performance improvements. (See this pull request for details.) If you are using byebug for debugging, you might want to upgrade!

Speeding Up Enumerable#sum

Did you know that Enumerable#{inject,reduce} can take a symbol as its argument? Apparently, this is slightly faster too! (Note: this is different from inject(&:method) which goes through Symbol#to_proc.)


Use Instead Of +…+ In Docs

Usually, you can use +some_word+ to switch to fixed-width fonts in Rails’ documentation. However, the parser for this rule would sometime fail in some more complex cases.

If you are not sure when to use which, be sure to check the guidelines, or just check the output locally by running rake rdoc.

Wrapping Up

That’s all for This week in Rails. As always, there are many more changes than we have room to cover here, but feel free to check them out yourself.

Until next time!

This week in Rails: new releases, exciting Rails 5 stuff and more!

Hey everyone - Tim here with another monster update with all the exciting Rails-related goings-on from this week.

Riding Rails: Snappier Development Mode in Rails 5

One of the nicest things about development mode in Rails has to be the sheer convenience of running on your latest revision on each request. This of course comes at a performance cost but is about to change: instead the filesystem will notify Rails asynchronously of any changes.

Rails 4.2.5 and 4.1.14 are here!

This week saw the release of both 4.2.5 and 4.1.14 versions of Rails. Go upgrade while they’re still hot!

This Week’s Rails Contributors

This week 33 fabulous people contributed to Rails. Check out the list of issues if you’d like to see your name up there.

New Stuff

New! days_in_year method added to Time

Now you can can call Time.days_in_year and, at the time of writing it will return 365. Call it next year and it will give you 366. Nice!

String#parameterize gets a preserve_case option

This change adds an option to Preserve-the-CASE of the string instead of casting-everything-to-lowercase when generating parameters.


Improve support for non Active Record associations on validation

Support for non-Active Record associations just got better by skipping marked_for_destruction? when going through validations if it’s not implemented, making it easier to define virtual associations.

Return a sized Enumerator from Hash#transform_values

You can now discover the size of a hash whose values have been transformed.


Exclude views when fetching tables on all the connection adapters

This brings more consistency across the adapters where those for MySQL and SQLite would return views in addition to tables when calling #tables, where PostgreSQL would not. Now they all return tables, and no views.

Wrapping Up

That’s all for This week in Rails. As always, there are many more changes than we have room to cover here, but feel free to check them out yourself.

Until next time!