Sunday, June 11, 2017

This Week in Rails: default option for mattr_accessor, write_multi and more!

Posted by prathamesh

Hello everyone! Prathamesh here bringing you the latest news from the Rails world. Let’s get started 🚅

🎉 This Week’s Rails contributors! 🎉

We had 21 awesome people who helped make Rails better this week. Two of them contributed for the first time ever! Would you like to help as well? Head over to the 👉 issues list.

New

💪 mattr_accessor gets the default option 💪

Followup to adding the default option to the class_attribute macro, it is now added to mattr_accessor family of methods as well.

It can be used as follows:

mattr_accessor :always_write_cookie, default: false

💪 Write multiple cache entries at once with write_multi 💪

A new method write_multi has been added to the cache stores which writes multiple cache entries at once.

For eg.

Rails.cache.write_multi foo: ‘bar’, baz: ‘qux’ The default implementation just calls write_entry one by one for each entry but specific cache stores can override this behavior as per their ability of doing bulk writes.

Fixed

⚡️ Generate field ids in collection_check_boxes and collection_radio_buttons ⚡️

This change fixes an issue with collection checkboxes and radio boxes where clicking on the labels was not selecting the options because the input elements did not have proper id attribute with respect to their labels.

✨ Fix partial cache logging getting attributed to wrong partials ✨

This commit fixes an issue with the cache hit/miss log markers being applied to wrong partials.

That’s it for this week, as always, we couldn’t cover all of the changes, but feel free to check all the commits from this week.

Until next week! 👋👋