Forum: Ruby on Rails Model Knowledge Of Controller Calling It

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
09ca7bd1bc03a735ed913a9de3f4370b?d=identicon&s=25 Mindtonic (Guest)
on 2009-03-02 20:10
(Received via mailing list)
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'.
170e2a48994775e4c298c302e6814f81?d=identicon&s=25 Starr Horne (Guest)
on 2009-03-02 20:22
(Received via mailing list)
> 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
B09a3f6cdc4797532647d2d264b5df49?d=identicon&s=25 Jodi Showers (jshow)
on 2009-03-02 20:30
(Received via mailing list)
Howdy -

On 2-Mar-09, at 2:21 PM, Starr Horne 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
09ca7bd1bc03a735ed913a9de3f4370b?d=identicon&s=25 Mindtonic (Guest)
on 2009-03-02 21:10
(Received via mailing list)
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!
This topic is locked and can not be replied to.