I'm currently developing a couple of modules to reuse code from my controllers on a Rails 3 using InheritedResources (last version) app.
My idea is to have some behavior that should be run after a successful create or update of the resource but, except from redeclaring the "create" or "update" actions, I'm not to sure on how to tackle this.
I'm currently using something like
module SessionStorable
extend ActiveSupport::Concern
include Base
included do
before_filter :setup_resource, :only => :new
after_filter :reset_session_resource_id, :only => [:create, :update]
end
# ....
end
I have a particular resource setup I use which, among other things, adds the id of the resource to the session. After the resource has being successfully saved to the BD, I'd like to remove it's id from the session and that is what the after_filter does.
I've deal with it so far by also saving the updated_at info onto the session and comparing to see if the model was updated (if so, it should have been successfully) and run the method.
However, I'm not to happy with it (kinda hacky) and also I'm planning on having other modules that will work with resources also after they've been updated and wouldn't want to use the same approach twice.
Is there a hook on IR that I should be using? Or any other ideas on how to proceed?