# Extending finders to include a session variable as an option?

**URL:** <https://www.ruby-forum.com/t/extending-finders-to-include-a-session-variable-as-an-option/168364>\
**Category:** Rails\
**Created:** [May 20, 2009, 12:16am UTC](https://www.ruby-forum.com/t/extending-finders-to-include-a-session-variable-as-an-option/168364 "2009-05-20T00:16:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![alan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a87d85/32.png) [@alan](https://www.ruby-forum.com/u/alan)\
**Post date:** [May 20, 2009, 12:16am UTC](https://www.ruby-forum.com/t/extending-finders-to-include-a-session-variable-as-an-option/168364/1 "2009-05-20T00:16:32Z")

</div>

We have a Page model which acts\_as\_paranoid.

AAP modifies ActiveRecord finders to ignore any records marked as  
deleted unless the :with\_deleted =\> true option is supplied.

We have a UI element which allows users to toggle whether or not to  
display deleted Pages, their current setting being stored in a session  
variable, session[:show\_deleted].

What we would like is to automagically have :with\_deleted =\> session  
[:show\_deleted] appended to all calls to find, all, first, find\_by\_  
etc.

That would be easy enough to do with an alias\_method\_chain but for the  
fact that session data is not available when the call is being made  
from a model.

I know accessing session data in a model is controversial, but can  
anyone suggest a workaround? Or alternatively another approach to  
being able to easily switch between including/ignoring deleted records  
in all finder methods?

Thanks.
