New attribute methods, regex matching and more!

Hello! Tim here with the latest scoop on Ruby on Rails!

New *_previously_was attribute methods!

Your models just got a sprinkling of a little extra sugar. For any given attribute that changed, you can now do:

Model.attribute_previously_was # => previous value

Support for matches_regex in MySQL

Check out this PR for a great example of how you can now perform regular expression matching on your MySQL queries!

Preservation of join order fixed

This fix managed to take down a number of open issues in one go! It addresses a recent regression by ensuring that the order of any user-supplied joins will be preserved as far as Active Record is able to do so.

28 people contributed to Rails last week, including 3 for the first time. If you’d like to see yourself up there, why not check out the list of open issues. Until next time!

ActionController::Base.log_at and more!

Hi there, this is Greg, bringing you the changes in Rails from the past week. Let’s dive in!

Reduce stat(2) calls

This commit adds a slight performance improvement by reducing stat(2) calls in Rails.

Serialize symbols to strings in ImmutableString serialize method

This PR updates the immutable string class to serialize symbols to strings to mirror this behavior as ActiveModel::Attribute calls this serialize method to determine the return value for changed_in_place?. Prior to this change, this code would wrongly report that “something” had changed.

Add ActionController::Base.log_at

This PR makes it possible to set a different log level on a per request basis. 

# Use the debug level if a particular cookie is set.  class ApplicationController \< ActionController::Base  log\_at :debug, if: -\> { cookies[:debug] }  end

25 peoplecontributed to Rails last week, if you want to be part of that, check out the open issues on Github.  Until next time.

Delete multi entries from cache, bugfixes and more

Hi. This is Wojtek. Rails 6 is with us for some time and we all can see it is a stable and solid release. Thank you one more time to all that tested the pre-releases and helped in ensuring that the final version is in a best possible shape.

Now let’s see some recent additions to Rails.

Added delete_multi method to Active Support Store Cache

Improves performance for deleting many entries at once when supported by underlying store like Redis.

Serialize classes and modules with Active Job

Classes and modules can now be passed to job as argument without a need for custom serializer.

Added email_address_with_name method to Action Mailer

Properly escapes email addresses with names without worrying if it includes special characters in it.

Fixed Range include? method for endless argument

Endless range was introduced in Ruby 2.6 and beginless range in upcoming Ruby 2.7.

Fixed Active Support Duration comparison

Guard against non numeric attributes to avoid faulty comparisons.

58 people contributed to Rails since the last time. You can check the full list of changes here. Until next time.

Rails 6 excitement, connection pool reaping, bug fixes

Greetings! Daniel here, reporting from Brooklyn, NY.

Rails 6 in the wild

I know we mentioned this last week, but I am so excited I wanted to mention it again. Rails 6 has been out for a little over a week and has had over 60,000 downloads. Check it out today!

Ensure connection reaper threads respawn in forks

I didn’t know much about this part of Rails before looking at this PR. The connection pool synchronizes thread access to database connections. The reaper continuously calls reap and flush on the connection pool. I have just one question: can somebody translate Aaron Patterson’s comment for me?

Avoid reaping parent connection pool after fork

This is from the same part of Rails as above. I really enjoyed seeing the collaboration between Guo Xiang Tan and John Hawthorn in these PRs. Nice work!

Fix memoization bug in Active Record

Anmol Arora noticed and fixed an Active Record bug that has been around for years. Excellent work on your first commit to Rails!

29 people contributed to Rails over the past week, including 8 first-timers. Check out the full list of changes, and if you are interested in helping out check out the open issues. Until next time…

Rails 6 is released, sass-rails 6, improved mysql2 error and more

Hello! This is Prathamesh bringing the latest news from the Rails community. This week we have some big news. Get ready.

Rails 6 is out!

After two and half years of development from more than 800 people having staggering 7275 commits, Rails 6 is released. Time to upgrade 😁
Check out the release notes and upgrading guide to know more.

Support for sass-rails 6

Rails now works with sass-rails 6.0. sass-rails 6 wraps sassc-rails gem under the hood. This new version stops usage of outdated and unsupported ruby-sass gem.

Make prepared statement status thread and instance-specific

This fixes a race condition in system tests where prepared
statements can be incorrectly parameterized when multiple
threads observe the mutation of the @prepared_statements
instance variable on the connection.

Improve MySQL error detection

Improve detection of ActiveRecord::StatementTimeout error with mysql2 adapter in the edge case when the query is terminated during file sort.

Log potential matches when asserting active job test helpers

Adds logging of potential matches when calling assert_enqueued_with and assert_performed_with  to provide more information about test failures.

25 people contributed to Rails in the last week. Want to see your name on that list? Check out the list of issues here.

See you next week.

Rails 6.0: Action Mailbox, Action Text, Multiple DBs, Parallel Testing, Webpacker by default, and Zeitwerk

Dealing with incoming email, composing rich-text content, connecting to multiple databases, parallelizing test runs, integrating JavaScript with love, and rewriting the code loader. These are fundamental improvements to the fundamentals of working with the web and building fast and fresh applications. This is the kind of work we’ve been doing for the past fifteen years, and we’re still at it. THIS IS RAILS SIX!

And that’s just the headline improvements! Since Rails 5.2 was released a little over a year ago, we’ve continued our high pace of improvement all over the framework. In 2019 alone, we’ve had 341 code contributors submit improvements and fixes. We’ve tried to summarize just some of the goodies in the release notes, but there are many more than that.

While we took a little while longer with the final version than expected, the time was spent vetting that Rails 6 is solid. In fact, GitHub, Shopify, and Basecamp, as well as plenty of other companies and applications, have been running the pre-release version of Rails 6 for months and months in production. We might not have caught everything, but if it’s good enough for GitHub, Shopify, and Basecamp, it’s probably good enough for you too!

So what are you going to get with Rails 6? Check it out:

Action Mailbox routes incoming emails to controller-like mailboxes for processing in Rails. It ships with ingresses for Mailgun, Mandrill, Postmark, and SendGrid. You can also handle inbound mails directly via the built-in Exim, Postfix, and Qmail ingresses. The foundational work on Action Mailbox was done by George Claghorn and yours truly.

Action Text brings rich text content and editing to Rails. It includes the Trix editor that handles everything from formatting to links to quotes to lists to embedded images and galleries. The rich text content generated by the Trix editor is saved in its own RichText model that’s associated with any existing Active Record model in the application. Any embedded images (or other attachments) are automatically stored using Active Storage and associated with the included RichText model. The foundational work on Action Text was done by Sam Stephenson, Javan Makhmali, and yours truly.

The new multiple database support makes it easy for a single application to connect to, well, multiple databases at the same time! You can either do this because you want to segment certain records into their own databases for scaling or isolation, or because you’re doing read/write splitting with replica databases for performance. Either way, there’s a new, simple API for making that happen without reaching inside the bowels of Active Record. The foundational work for multiple-database support was done by Eileen Uchitelle and Aaron Patterson.

With parallel testing support, you can finally take advantage of all those cores in your machine to run big test suites faster. Each testing worker gets its own database and runs in its own thread, so you’re not pegging one CPU to 100% while the other 9 sit idle by (y’all do have a 10-core iMac Pro, right 😂). Hurray! The foundational work for parallel-testing support was done by Eileen Uchitelle and Aaron Patterson.

Webpacker is now the default JavaScript bundler for Rails through the new app/javascript directory. We’re still using the asset pipeline with Sprockets for CSS and static assets, though. The two integrate very nicely and offer the best trade-off of advanced JavaScript features with an it-just-works approach to other assets.

Xavier Noria’s new Zeitwerk code loader for Ruby. No more const_missing, no more code loading gotchas, hello Module#autoload!

Those are just some of the marque additions, but Rails 6.0 is also packed with minor changes, fixes, and upgrades. Just some I’d call out: Proper Action Cable testing, Action Cable JavaScript rewritten in ES6, protection against DNS rebinding attacks, and per-environment credentials. Also, Rails 6 will require Ruby 2.5.0+ now. You can check out everything in the individual framework CHANGELOG files for the nitty-gritty rundown.

This release was shepherded by release manager Rafael França with support by Kasper Timm Hansen.

Thanks again to everyone who keeps working on making Rails better! Thanks to everyone who uses Rails! I’m incredibly proud to see this open-source framework continue to thrive outside the pressures of market terms and reciprocal guilt. This is a gift we give each other and expect nothing in return.

Rails 6.0.0 rc2 released

The final version of Rails 6.0 is almost ready, but before we put a pin in it, please enjoy this second release candidate. We’ve cleared all the blockers that were discovered during the first release candidate, and if nothing new and major is discovered, we’ll ship the final release in a couple of weeks.

There has been 172 commits of changes since rc1.

You can read all about what’s new in Rails 6.0.0 in the first beta announcement. From Action Mailbox to Action Text, multiple database support, parallel testing, and Webpacker handling JavaScript by default. This is a massive step forward for Rails.

This release, and all releases leading up to Rails 6.0 final, was shepherded by release manager Rafael França with support by Kasper Timm Hansen.

Active Storage, startless range in queries, SMS links and more!

Hello! This is Roque bringing the latest news from the Rails community. It’s been awhile so let’s see what has changed since then… Oops, since last week 😜

Preserve existing attachment assignment behavior for app upgraded to Rails 6.0

Assigning a collection of attachments appends to the collection as it did in 5.2. Existing 5.2 apps that rely on this behavior will no longer break when they’re upgraded to 6.0. For Apps generated on 6.0, assigning replaces the existing attachments in the collection. #attach should be used to add new attachments to the collection without removing existing ones.

Support startless ranges in queries

Add support to startless ranges (e.g. ..10 and ..Date.today), introduced by Ruby 2.7.0-preview1, to Active Record queries. This enables expression like Order.where(created_at: ..1.year.ago).

When the users click the SMS link, their messaging app opens with the phone number and optional message body set in the link.

Superclass for aborted queries

The class ActiveRecord::QueryAborted makes it possible, for example, to rescue all possible query timeouts without rescuing other query exceptions.

Add --skip-collision-check option to the Rails generator

This allows the generator for 6.0 to behave like it used to in 5.2, and overwrite files.

18 people contributed to Rails in the last week. Want to see your name on that list? Check out the list of issues here.

Until next time!

New contributors fixing bugs in the summer

Hey all! This is Daniel from Brooklyn, NY bringing you the latest news in Rails.

Add database_exists? method to connection adapters

The database_exists? method does what you might think—it checks whether a database exists. This will help in resolving some inconsistencies between SQLite and the other database adapters.

Share column and table names between connections

Sharing is a beautiful thing. Since connection instances are likely to share table and column names, we can store them on the class instead of on each instance. Isn’t that nice?

Fix query cache when using shared connections

Congratulations to Heinrich on their first commit to Rails!

Fix bug when combining order with exist?

Congratulations to Takayuki on their first commit to Rails!

21 people contributed to Rails in the last week. Want to see your name on that list? Check out the list of issues here.

Be well!

Schema dump fix and database task creation improvements!

Hi there. This is Greg bringing you latest news from the Rails world. We had a quiet week, so I won’t take long.

Fix schema dumping for enum and set columns in MySQL

With this change Active Record will use the sql_type rather than type, in the database dump for enum and set columns to make sure they use the correct type.

Warn if database tasks can’t be created

With this change, Rails loads the initial database.yml once, and warns if it can’t create tasks. This is important for multiple databases, where the tasks are created for every database, but to create those Rails needs to read the list from database.yml.

9 people contributed to Rails in the last week, if you want to be one of them, check out the list of issues here.

Until next time!