Friday, February 20, 2015

This week in Rails: http_cache_forever, AR::Base.suppress and more!

Posted by claudiob

My Valentine’s Day letter to Ruby on Rails:

“Dear Rails, remember the first time we met?
You were just 1.2, and I was in an unhealthy relationship with Perl and PHP.

I saw you in the library and I immediately fell in love.
For seven years, you made my code more readable and my skills stronger.

You are the most beautiful framework and always will be.
I cannot wait to see you turn 5.0.” – Claudio

This Week’s Contributors

Apparently I’m not the only one in love with Ruby on Rails. 36 programmers contributed to Rails this week, 10 of them for the first time. Keep loving!

New Stuff

Add http_cache_forever to ActionController

The new method is perfect to cache results that are meant to never expire, such as static pages.

Add ActiveRecord::Type.register

You can now reference with a symbol any database type that is specific to your adapter, such as:
ActiveRecord::Type.register(:money, MyMoneyType)

Add ActiveRecord::Base.suppress

Wrapping a block with suppress will prevent any save operation from hitting the database. Check the PR for a real-world example.

Improved

Add :time option to ActiveRecord::Base.touch

You can now touch an ActiveRecord instance with a different time than the current time.

Removed

Removed RecordTagHelper

The helpers div_for and content_tag_for will be gone in Rails 5. Grab the record_tag_helper gem if you still need them!

Removed ActiveModel::Errors getters/setters

If you ever used person.errors.get(:name) or person.errors[:name] to read an error message, you should now switch to person.errors.messages[:name]. add_on_empty and add_on_blank are gone too.

Update: you should be using person.errors[:name] after all! Use person.errors.add(:name, ...) to append.

Wrapping up

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

P.S. If you enjoyed this newsletter, why not share it with your friends? :) If you wish to be part of this project please don’t hesitate to contact Godfrey – there’re a lot of ways you could help make this newsletter more awesome!