June 04, 2008 by alex
Here are some things that change in rails you shold be aware of.
If you are using custom callbacks for you rails observer you now have to tell rails about these callbacks first. Simply add a
define_callbacks :your_callback, :your_other_callback in models with custom callbacks.
The call to register custom template handlers in the enviroment has changed from
ActionView::Template.register_template_handler. With a custom handler you can output pdfs for example.
ActionController::MissingTempalte Error was moved to
With the new Caching in place the config call changed from
cache_store to reflect the new unified caching infrastructure.
If you have included the Observable mixin in one of your ActiveRecord models, like we did before we learned to harness the power of
ActiveRecord::Observer, it’s time to abandon these because the
changed method overwrites the new
changed of ActivRecords dirty tracking. So if your stack trace look similar to this…
Observable overwriting the ActiveRecord
What also comes with dirty tracking is, that a save call does nothing unless someting really changed. Although this is the desired behavior, it might break logic where you rely on the old behavior, e.g. when you just want to update the time stamps of an object in the database. You can tell the object with
attr_name_will_change! that an attribute should be written to the database.
Another ActiveRecord change we found is that
:dependent => true isn’t supported anymore although I don’t remember a deprecation warning. Just use
:dependent => :nullfiy|:delete|:destroy.
But now let’s come to some nice stuff we discovered.
ActiveRecord now complains with a
stack level to deep if you have circular dependency behaviors defined, eg. User has_one :profile, :dependent => :destroy and Profile belogs_to :user, :dependent => :destroy. Such logic can just be the result of isolated late night coding, so an error is the desired behavior in my opinion.
Let’s get back to the aforementioned
changed method. Because it returns an array of changed field names, it is a good way to fire after save actions only if a specific field changed. For our autoki application it is a good way to fire some image processing task only if the auto picture changed.
At the end comes the real nasty stuff. Rails 2.1 really wrecks havoc under the plugins we are using. As you might guess the most have to do with caching.
While the fragement_cache_test plugins error
uninitialized constant ActionController::Caching::Fragments::MemoryStore can be fixed relatively easy by changing the base class for the
ActiveSupport::Cache::MemoryStore and the calls to
reset have do be changed to
clear the timed_fragment_cache plugin and the extended_fragment_cache are rendered useless until updated, which we don’t expect to happen, so we put together the local_cache_plugin as a resplacement for both.
Will_paginate requires an update from git, and it will play nice again. It resides on github now and can be installed with
script/install git://github.com/mislav/will_paginate.git thanks to the install script git support.
The paginated search plugin for ferret will require an update too, because of the changes in will_paginate. But it’s still maintained so just grap the new code from the opensoul blog.
So that’s all for now. (Wow this post got big)
We aren’t finish yet so we will post more while we find other noteworthy changes.