This Week in Rails: greener JRuby, optimistier locking and more!

Hey peeps, Kasper here.

It’s that time of the week again, when that newsletter you read while frantically checking is here.

Oh, you think we’re down, cupcake? I’m afraid that’s just you buddy, we’re fired up and ready to go!

This weeks Contributors

Did you know you can contribute to Rails? Oh, I’m not kidding! It’s totally open source and everything.

In fact check the next item if you’re looking to join the list, codeslinger!

JRuby turns Rails green with envy

Before RubyConf the JRuby team would like to get the whole Rails test suite passing and green.

Already some fixes have been committed. Check out the linked tweet and see if there’s something you can help with.


Optimistic locking unlocks overriding

If you’d been a good sport and optimistically tried to set the lock column value, you’d be sorry. Now you would be happy because it’s fixed!

Allow any key in Renderer environment hash

Since Rails 5 you’ve been able to render templates outside of your controller actions. Now you can pass in arbitrary keys when performing that kind of rendering.

Publicize process in controller tests

In your ActionDispatch::IntegrationTest controller tests you can use the get etc. request shorthands which would just pipe through to a private process method.

Now that method is public so you can better see the documentation on it.


Prevent test framework from loading in production

Some dingus accidentally caused minitest to be loaded in the production environment.

Luckily that’s fixed now!

Wrapping up

That’s it for this week, as usual there were more changes than what we can fit, feel free to check them yourself here. Until next week!

This Week in Rails: onward, we go!

Happy Friday from sunny Los Angeles!

Claudio here with the latest news from the rails/rails repository. Here’s a recap of the commits and pull requests merged into master this week.

This week’s Rails contributors

14 programmers contributed to Rails this week, two of the them for the first time. If you haven’t contributed yet, I hope you will join the list next week.


ActionCable now permits same-origin connections by default

Same-origin connections are now permitted by default. If you want to stick with the old behavior, you can set config.action_cable.allow_same_origin_as_host = false 

explain why autosave= disables inverse_of

autosave and inverse_of do not get along together, since they may for example cause double saves.


Work around read/close race

If one thread calls close on an IO at the same time that another calls read, segfaults might have occurred. This has now been fixed!


Fixnum and Bignum are deprecated in Ruby trunk

A small upgrade to the Rails codebase to have it ready for the upcoming release of Ruby 2.4 which has deprecated Fixnum and Bignum.

Remove deprecations in Active Model, Action View and Active Job

And in Action Pack too. Methods that were deprecated in Rails 5.0 will be gone once Rails 5.1 ships.

Wrapping up

That’s it for this week, as usual there were more changes than what we can fit, feel free to check them yourself here. Until next week!

This Week in Rails: Getting Ready For Ruby 2.4

You are reading This Week In Rails!

This week’s Rails contributors

The content for this week’s newsletter is sponsored by the 19 individuals who authored them!

Fixnum and Bignum are deprecated in Ruby 2.4

One of the notable changes in the upcoming Ruby 2.4 release is the unification of Fixnum and Bignum into a single Integer class. Following that change, the legacy classes were deprecated recently.

This pull request avoids triggering those deprecation warnings with a feature detection. If you maintain code that references those constants, you might want to adopt this pattern in your projects too!

Remove json gem dependency

Related to the unification of the integer classes: native extensions that references the rb_cFixum and rb_cBignum C constants need to be updated as well.

The popular json gem is one of those native extensions. Fortunately, all modern versions of Ruby bundles the json library. If your are targeting Ruby 1.9 and above, you could simply remove the json gem as a dependency.


Avoid bumping the class serial

Back in May, a regression was reported that Rails 5 invalidated Ruby’s class_serial on each request. This internal counter is used to invalidate the class-level method caches.

The issue was tracked down to the use of instance_exec. While there is hope that this restriction could be relaxed inside Ruby itself, this patch at least temporarily fixes the problem on Rails’ side.

Speed up

Once upon a time, could be quite a bit slower than the stock (allegedly up to 25 times slower). This pull request significantly closes the gap.


Avoid compiling ruby keywords into template locals

Have you tried rendering a partial while injecting local variables called “class” or “module”? It wouldn’t work, and it will give you a pretty bizarre error.

This pull requests avoids the error by skipping over invalid local variable names, while still allowing them to be accessed via local_assigns.

You can read more about this issue, as well as the story behind this pull request in Peter’s blog post.


Remove undocumented Action Cable “faye mode”

Did you know that there was an undocumented “faye mode” for Action Cable?

No? Good. Because it’s now gone!

Wrapping up

That’s it for this week, as usual there were more changes than what we can fit, feel free to check them yourself here!

Until next week!

This Week in Rails: cable got buffer, callbacks stripped, and more!

Cadet, you’re at the new frontier! Orbiting the red planet just yonder, you ponder and wonder:

Do Martians drink their Martinis on the rocks?

All this crew member knows is that he prefers his scoops on the Rails — good news, everyone: We’re setting course for such a delivery!

This Week’s Multiplanetary Contributors

22 contribunauts came aboard the contributor list this week with their precious commits harvested for the good of all. You’ve earned this heart of gold: 💛

Action Cable buffers socket writes

Quoting the description:

Sockets can sometimes block, leading to reduced system throughput as threads get tied up.

Switching to incremental writing allows Action Cable to spread out writes such that a blocked socket can’t block writes to other sockets.

Callbacks leaves less backtrace lines

Callbacks — before_action and friends — moved forward by going back this week: back to the backtrace and removing traces of itself. Try that, McFly!

Check the description for an example, it’s quite easier to see in action.


Rails’ test runner supports after_run hooks

The Rails test runner switched to using minitest’s autorun across the board, as such it gained support for Minitest.after_run hooks.

autorun also guards against running tests twice, which could happen in some cases. But that’s now fixed too.


Don’t leak ActiveModel::Errors default_proc

Previously when serializing ActiveModel::Errors via to_hash or as_json for instance, the default_proc would hide in the engine compartment and spring out when the crew was out of orbit.

No more of those alien capers on this ship!

Make :as option also set request format

In Rails 5 you can make an as of your test requests, as: :json that is.

After adding the option to ActionController::TestCase last week, we’ve opened the pod bay doors once ensuring the format is just right_._

Wrapping up

That’s it for this week, as usual there were more changes than what we can fit, feel free to check them yourself here!

Until next week!

This Week in Rails: 🍫 Your Golden Ticket to the Chocolate Factory 🍫

Jon here welcoming you to This Week in Rails!

Today we’ll be touring the wondrous Ruby on Rails chocolate factory to see how its marvelous candy, consumed by web apps and developers everywhere, is made and tested.

Golden tickets in hand? Let’s go!

Welcome! 🎩

This Week’s Rails Contributors

This week, 26 fabulous oompa-loompas concocted improvements to make your favorite candy even more delicious – including one for the first time!

Fix Bundler warnings about insecure github sources

If you upgrade to bundler 1.13 and use github options to specify gem sources in your Gemfile, you’ll see warnings when running bundle commands.

To fix, you can run bundle config github.https true on the command line.

Or if you don’t control the environment the Gemfile will execute in, you can add this to the Gemfile, like Rails now does:

git_source(:github) |repo_name| do

Backported to 5-0-stable.

Improving the chocolate 🍩🍫

Puma docs: Disconnect connections before preloading

This pull request added documentation for config/puma.rb to recommend closing database connections if preloading an application that uses Active Record. See the discussions in the pull request and in puma/puma#1001 for more.

Improve assert_response helper

To improve productivity when writing tests, if an assert_response test fails, Rails nows outputs the actual response body if it’s not too large (less than or equal to 500 chars).

Fixing bugs in the candy 🍬

Clear attribute changes after touching

Following-up on a very good bug report, this PR fixed a Rails 5 regression so that calling ActiveRecord#touch when using optimistic locking once again leaves the model in a non-dirty state with no attribute changes.

Prevent mutation of constants

Tests using ActionDispatch::IntegrationTest were failing when run after any controller test that modified request.session_options. It turned out that  ActionController::TestSession::DEFAULT_OPTIONS was being mutated, and as a result, Rack::Session::Abstract::Persisted::DEFAULT_OPTIONS also, which made integration tests inherit that value and fail.

This pull request dup’ed the AC default options constant to prevent mutation, and a pull request to Rack was merged to freeze the Rack default options constant and avoid the issue in the future.

Force correct namespace with TransactionManager

This pull request fixed issue #26441: “NameError: uninitialized constant AR::ConnectionAdapters::DatabaseStatements::TransactionManager when calling reset_transaction”.

How to contribute? Some examples from this week 🍰

Fix warnings in the test suite

Running the Rails test suite can be a great way to uncover minor issues to fix. This pull request addressed 2 warnings in the test suite that arose simply from not wrapping a method argument in parentheses.

Add missing tests

Noticing that there were no tests for when ActiveRecord::Enum#enum was called with a specific suffix, this contributor added some.

Improve the Rails Guides

Better documentation is always welcome. After seeing issue #26286, this contributor helpfully improved the documentation for the render partial ‘as’ option.

Add a bug report template

The commit message says it all: “I created this for testing migrations in isolation and thought it would be helpful to others in the future to avoid having to dig through the Rails migration tests.”

Remove duplicate code

This elsif branch was a duplicate of the else branch just after it. You’ll never believe what happened next 😮.

How to inherit a world of unlimited imagination 🍭

That’s it for today’s tour, but the true journey has only just begun.

Starting today, choose any file in the Rails codebase and read it.

Pick an open issue on the master branch, and try to reproduce the bug using the Rails bug report templates.

Go through the Contributing to Ruby on Rails Guide. Set up your Rails test environment.

Pick an open pull request and test it or review it.

You’ll be surprised what baby steps like these can lead to!

Enjoy the wonderful chocolate – and see you next week.

This Week in Rails: Ruby 2.4 compat, attachments in preview emails, fixture_file_upload and more!

Howdy everyone!

This is Prathamesh bringing you the changes from this week in Rails!

This Week’s Rails Contributors

This week we had 22 awesome people making Rails better. We also had 3 people contributing for the first time. 

One more step towards Ruby 2.4 compatibility

Ruby 2.4 is coming! If you have already tried it with Rails 5, a key must be 32 bits error was raised due to a breaking change in Ruby 2.4 related to openssl cipher key lengths. It is now fixed, while keeping backward compatibility with any existing signed data. 🎉


Allow download of email attachments in the Mailer Previews

Now we can download email attachments in mailer previews similar to real-world emails thanks to this change.


Make fixture_file_upload work in integration tests

This change makes sure that the  fixture_file_upload   test helper works properly in integration tests. In case you missed it, integration tests are the default way of testing controllers in Rails 5.

Use proper test adapter for Active Jobs inheriting from ApplicationJob

Rails 5 introduced ApplicationJob as the default base class for Active Job classes. When testing these classes, the proper test adapter was not being invoked due to looking for subclasses of ActiveJob::Base instead of its descendants. This change fixes it.

Wrapping Up

Although I enjoyed reviewing all the commits from the last week, there were as usual too many to mention exhaustively. But do check them out yourself here!   Until next week!

This Week in Rails: Speedier Times, Explicit Public Assets and more!

Oh, hello there!

This is Tim here bringing you your latest installment of This Week in Rails. We had another corker this week chock full of great updates - read on for the full details!

This Week’s Rails Contributors

This week saw 99 commits from 27 fantabulous people contributed to Rails, including an amazing 5 first-timers! If you’d like to see your name up there next week, why not take a gander at the issues board, or you may even consider the next item for inspiration….

Documentation Galore

This week saw a whopping 11 documentation PRs successfully merged. Improvements to the documentation are not only gratefully received, but are a great way to start getting involved.


Make public asset use explicit

When calling asset_path with an invalid file name, this method would simply pass the string that you gave it back to you. This revision adds a configurable flag called unknown_asset_fallback which when set to false will raise an error if the asset is not found. Setting it to true will preserve the current behavior, but will indicate that it is being deprecated.

Don’t unnecessarily load a belongs_to when saving

This change prevents an already-loaded model from being reloaded if its id gets assigned to another model in a belongs_to association and then saved.


Fix performance regression in TimeWithZone#to_time

Up until Rails 4.0.0.beta1, TimeWithZone#to_time could return a cached instance attribute. Since that release it has been coercing the value to a Time on each call. This revision reverts the old behavior, which, according to the author’s benchmarks, is over 5 times faster.

Allow send_file to declare a charset

Previously, calling send_file with type: "text/calendar; charset=utf-8" , would result in the charset’s being deleted - a bug that was fixed in this PR.

Wrapping Up

Although I enjoyed reviewing all the commits from the last week, there were as usual too many to mention exhaustively. But do check them out yourself here!

Until next week!

This Week in Rails: Bad Puns, Dad Jokes And Other Useless Information!

Hello there!

Yes, this is Godfrey again. I am glad a lot of you found last week’s Cool Trick™ useful. However, wouldn’t life be pretty boring if you just keep getting useful information? So I figured I would change things up a bit by delivering you an issue full of bad puns, dad jokes and other useless information. Let’s get to it!

This Week’s Rails Contributors

This week, 11 new contributors along with 19 other returning contributors took some time to keep Rails chugging along.

Include The Content of “The Flash” In ETags

When confronted about code bloat, DHH does not take it lightly. This week, he pulled another one of those moves by committing the content of The Flash into the Rails codebase.

Redirect POST Requests With 307 Status Code

Chirag Singhal decided to stir up some drama here by sending browsers a HTTP 307 “YOU JUST DON’T GET IT” status code when upgrading POST/PUT/DELETE requests to HTTPS connections.

Remove over meta programming in AR::Relation

When Bogdan Gusiev dived into the AR::Relation code base, he was not pleased with what he saw. After making some tweaks in this PR, he seemed happy with the result. Why?


( •_•)>⌐■-■


It doesn’t meta anymore.


Improve tag_option performance

Amadeus Folego identified  tag_options  as a hotspot in his application and decided to help improve its performance by throwing in some frozen strings. Cool!

Update docs with Action Cable Redis dependency

Coming back from his vacation, Rafael Reggiani Manzo redis™covered a new dependency for developing Rails. To ease the shock for the next person, he added the setup instructions to the guides.

Missing key should throw KeyError

Last but not least, Eileen M. Uchitelle committed a key error this week.

Wrapping Up

That’s all from me this week, I hope you find this information useless! For a more informative view, check out (no pun intended) the commits here.

Okay, please don’t unsubscribe! 😭 Your favorite rotation of editors will be back starting next week to replace me, so I’m sure things will get better from here!


This Week in Rails: Read Me To Learn A Cool Trick™!

This is Godfrey, reporting in from Portland, OR. We have a lot to cover this week, let’s dive right into the stories so you can go back to watching Olympics!


Cool Trick™

Router Visualizer

Have you ever wondered what happens when you visit a URL (say /posts/5 ) in your Rails app? How does the Rails router know where to send your users?

The first (of many) step is to compare the URL against the routes table for potential matches. To make this lookup as fast as possible, the routes table is pre-compiled into a finite state machine, specifically a nondeterministic finite automaton (NFA).

If that sounds very intimidating, don’t worry! The Rails router actually comes with a debugging tool that could generates an interactive visualization of your router NFA.

To generate one for your app, simply run Rails.application.routes.router.visualizer from your Rails console and save the returned string into an html file. (You will need the dot command-line tool for this – OS X users can get it from homebrew with brew install graphviz. )

Oh, is it not working? I forgot to mention that this tool is broken on Rails 5 by an internal refactor. Don’t worry though, because Seth fixed it for us in this pull request, which would come out with the next 5.0 patch release. If you are impatient, you could try it out by running the 5-0-stable branch.

Before you build your next billion-dollar startup with this awesome tool, please note that this is an undocumented ( private! ) API, and as you can see, could break unexpectedly between versions (or go away entirely).

While it’s definitely not Production Grade™ software, it’s still very useful for learning and debugging purposes. Enjoy it while it lasts!

New Stuff

Optional schema.rb Alignment

When dumping the schema, Rails tries to align things vertically for readability. However, this could result in a bigger diff than you would like when making changes to an existing table. With this PR, you now have an option to turn that off!

Controller Tests Now Supports as Option

While integration tests are strongly preferred over controller tests going forward, this PR allows you to simulate a request content type in controller tests using the same as: :json (or as: :xml , and so on) option. 

retry_on Gets A Job

Active Job’s retry_on API can now access to the job instance that failed, in addition to the exception object.

Make touch_later Respects no_touching

The no_touching API now composes correctly with touch_later as you would expect.

Query With Arrays and Ranges

With this PR, you will be able to pass an Array or Range object to where(some_column: …) when querying an array/range column, assuming your database supports those column types.

Fix Upgrade Task Documentation

This is a periodic PSA that when it comes to upgrading Rails apps, the update task is going to be your friend. In Rails 5, this command has been renamed to rails app:update , whereas when upgrading to Rails 4.2 and below, you would want to use rake rails:update instead.

See the upgrade guide for more details.

In Case You Missed It…

Active Job Defaults To Async Adapter

In case you missed it, Active Job in Rails 5 defaults to using the “async” adapter for jobs processing (the previous default was the “inline” adapter). The documentation has been updated to reflect that change.

Wrapping Up

That’s it from This Week in Rails! As always, there were a lot more changes than we have room for. If you are interested, definitely go check them out yourself!

Until next week!

This Week in Rails: params encoding, better logging and more!

Hello! This is Roque covering latest events from the Rails community. Like in Rio, our week was busy with plenty of amazing participants #Rio2016 🇧🇷

Security releases!

New Rails versions are released with many important security fixes. If you have not done already, do not drop the ball and upgrade as soon as possible.

This Week’s Rails Contributors

This week 29 code athletes contributed to Rails. We also got 1 first time contributor. Welcome aboard the Rails Games!

Allow specifying encoding of parameters by action

Controllers can list the parameters with parameter_encoding, providing the action and the encoding type.
This allows parameters in the same request to have particular encoding types.


Fix thread_mattr_accessor class leaking

thread_mattr_accessor was sharing the variable with superclasses and subclasses. Setting the variable in one would compromise the other.

Fix the Accept header overwritten issue in integration tests

XHR integration tests were overwriting the Accept header and creating inconsistency with HTTP_ACCEPT.


Better logging of cached partial renders

A while ago, DHH suggested an improvement to better log cached partial renders. It looks pretty clean!

Show error message when Rails runner fails

The Rails runner will now give you a hint of what is going on whenever it fails with an exception.

Wrapping Up

That’s it from This Week in Rails! There were many other great code athletes, too numerous to list here, but feel free to check them out!

Until next week!