Getting access to request.env in a model observer?

Does anyone know how I would get access to the request.env object
within a model observer? I’m using restful_authentication to send
email, and need to include some of that request data in there.

I have it working with normal ActionMailer stuff, but can’t figure out
how to do it in an observer.

Thanks,
Wade

You can’t. Request information is related to controllers and views and
should not be made available to models.

Look at Restful authentication and see how it handles that - they use
attr_accessor to store data.

This is a really dumbed-down approach but you could do this:

class ModelObserved < AR::Base

attr_accessor :request_info

rest of your code

end

class ModelObservedObserver < AR::Observer

observes ModelObserved

def after_save(record)
unless record.request_info.blank?
# do stuff with this
end
end

end

Then in your controller you just need to make sure you pass the
request.env
stuff to the model.

The other way to do it is to use cache_sweepers instead of observers.
Acts_as_audited does that so you might learn something from that code.

On Thu, Jul 17, 2008 at 1:03 PM, H. Wade M. [email protected]

Thanks - I used an attr_accessor and it seems to do the trick!

–Wade