# Model Knowledge Of Controller Calling It

**URL:** <https://www.ruby-forum.com/t/model-knowledge-of-controller-calling-it/161818>\
**Category:** Rails\
**Created:** [March 2, 2009, 8:10pm UTC](https://www.ruby-forum.com/t/model-knowledge-of-controller-calling-it/161818 "2009-03-02T20:10:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mindtonic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f19dbf/32.png) [@mindtonic](https://www.ruby-forum.com/u/mindtonic)\
**Post date:** [March 2, 2009, 8:10pm UTC](https://www.ruby-forum.com/t/model-knowledge-of-controller-calling-it/161818/1 "2009-03-02T20:10:56Z")

</div>

Does anyone know a good way for a Model to be aware of which  
Controller is calling it? For example, I have an after\_find method  
that should always be called unless the Controller is the  
‘FooController’.

---

<div class="post-metadata">

**Author:** ![mindtonic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f19dbf/32.png) [@mindtonic](https://www.ruby-forum.com/u/mindtonic)\
**Post date:** [March 2, 2009, 8:22pm UTC](https://www.ruby-forum.com/t/model-knowledge-of-controller-calling-it/161818/2 "2009-03-02T20:22:15Z")

</div>

> Does anyone know a good way for a Model to be aware of which  
> Controller is calling it? For example, I have an after\_find method  
> that should always be called unless the Controller is the  
> ‘FooController’.

This doesn’t sound like such a good idea. Isn’t the whole point of the  
MVC architecture is that the models are separate from the controller?

SH

---

<div class="post-metadata">

**Author:** ![mindtonic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f19dbf/32.png) [@mindtonic](https://www.ruby-forum.com/u/mindtonic)\
**Post date:** [March 2, 2009, 8:30pm UTC](https://www.ruby-forum.com/t/model-knowledge-of-controller-calling-it/161818/3 "2009-03-02T20:30:37Z")

</div>

Howdy -

On 2-Mar-09, at 2:21 PM, Starr H. wrote:

> > Does anyone know a good way for a Model to be aware of which  
> > Controller is calling it? For example, I have an after\_find method  
> > that should always be called unless the Controller is the  
> > ‘FooController’.
> 
> This doesn’t sound like such a good idea. Isn’t the whole point of the  
> MVC architecture is that the models are separate from the controller?

I suggest you consider what it means in the problem domain to come  
from that controller - ie. is that an admin controller, thus  
administrating is the consideration?)

If so the issue is about admin access - not the controller -ie the  
controller is immaterial, and admin access may be achieved through a  
web service, not through this controller, but another way to designate  
admin access.

I hope the above isn’t confusing - the domain is what you should be  
concerned about - not the implicit considerations based on the  
technology (controller).

J

---

<div class="post-metadata">

**Author:** ![mindtonic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f19dbf/32.png) [@mindtonic](https://www.ruby-forum.com/u/mindtonic)\
**Post date:** [March 2, 2009, 9:10pm UTC](https://www.ruby-forum.com/t/model-knowledge-of-controller-calling-it/161818/4 "2009-03-02T21:10:37Z")

</div>

Valid point… I forgot about the whole autonomy thing, silly me.

Here is the real reason, perhaps someone has an idea… I am loading  
feeds. I have a after\_find method called read\_feed that check to see  
if we need to reload the feed cache and update the information. This  
all works great on the majority of the site. However, when working in  
the feeds admin area, even with paging, we are loading 30 feeds at a  
time for admin purposes, and if they all need to be recached, it can  
take a long time for the page to render.

So what I want is a way to disable automatic caching for the admin  
area only.

One idea is to invoke the initialize method in the feeds controller,  
and set a switch on the Model to do\_not\_cache, but I thought this  
might get a little but messy.

Any other ideas or suggestions?

Thanks!
