Ruby Forum Ruby on Rails > Trouble with controller caching

Posted by peter@rawnet.com (Guest)
on 21.09.2007 12:25
(Received via mailing list)
Hi All!

I have an application with a frontend and admin backend. In both
sections there are controllers with the same name (e.g.
CampaignsController and Admin::CampaignsController). The front and
backend controllers have seperate authentification methods (for users
and admins). When a admin browses to admin -> campaigns they are
redirected to the frontend login screen as if they had browsed to the
frontend campaigns controller. The problem is solved when product.rb -
> config.cache_classes is set to false OR when all the admin
controller names are prefixed with 'Admin' (e.g.
Admin::AdminCampaign). Is there any other way I can get around this?
has anyone else experienced this problem?

Many Thanks,
Peter
Posted by Pratik Naik (pratik)
on 21.09.2007 12:39
(Received via mailing list)
Did you try this in edge rails ?

On 9/21/07, peter@rawnet.com <inneroptics@gmail.com> wrote:
> > config.cache_classes is set to false OR when all the admin
> controller names are prefixed with 'Admin' (e.g.
> Admin::AdminCampaign). Is there any other way I can get around this?
> has anyone else experienced this problem?
>
> Many Thanks,
> Peter
>
>
> >
>


--
Cheers!
- Pratik
http://m.onkey.org
Posted by Roderick van Domburg (roderickvd)
on 21.09.2007 13:00
Pratik Naik wrote:
> Did you try this in edge rails ?

Indeed you should. Namespacing of controllers has been a pain in Rails 
<= 1.2 but Rails 2.0 does offer support for namespaced controllers. In 
config/routes.rb:

map.namespace(:admin) do |admin|
  admin.resources :campaigns
  ...
end

--
Roderick van Domburg
http://www.nedforce.com
Posted by peter@rawnet.com (Guest)
on 21.09.2007 15:04
(Received via mailing list)
Thanks for the quick replies.

I thought before I tried edge rails that I would replicate the problem
locally. So I've run the app using the production env and using
mongrel instead of webrick, all the versions are the same yet the
problem doesn't appear. Any ideas?

Peter

On Sep 21, 12:00 pm, Roderick van Domburg <rails-mailing-l...@andreas-
Posted by peter@rawnet.com (Guest)
on 21.09.2007 15:24
(Received via mailing list)
I'm also seeing this in my mongrel logs on the server:

/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/
active_support/inflector.rb:250: warning: toplevel constant
CampaignsController referenced by Admin::CampaignsController

Any ideas?

Peter
Posted by Pratik Naik (pratik)
on 21.09.2007 15:25
(Received via mailing list)
Pastie your code

On 9/21/07, peter@rawnet.com <inneroptics@gmail.com> wrote:
>
> > On Sep 21, 12:00 pm, Roderick van Domburg <rails-mailing-l...@andreas-
> > >   admin.resources :campaigns
>
--
Cheers!
- Pratik
http://m.onkey.org
Posted by Jared (Guest)
on 19.11.2007 21:52
(Received via mailing list)
Peter & all,

Was a solution ever found for this? I'm running on Edge Rails (2.0 RC
1) and I'm encountering the same thing, only in production, and only
intermittently.

When mongrel has been running for "a while" I start to run into this
same problem, where I have EventsController and
Worker::EventsController.  The latter doesn't require authorization,
but links to /worker/events start directing to /events, which in turn
leads to a filter chain halt due to a lack of authorization.

Even more oddly, if I access /worker/events/, I'm redirected properly
to Worker::EventsController, but if I leave off the trailing /, I get
bounced out.

I'm seeing the following in my Mongrel Logs:

/var/www/apps/workerlogic/releases/20071116212637/vendor/rails/
activerecord/lib/../../activesupport/lib/active_support/inflector.rb:
257: warning: toplevel constant EventsController referenced by
Worker::EventsController

Any thoughts would be appreciated!

- Jared
Posted by Jack Dempsey (jack)
on 25.11.2007 23:14
(Received via mailing list)
I've had the same happen to me; you've hit it on the head exactly with
the "a while" type behavior. Its really perplexing, and I can't think
of what might be going on.

The trailing slash thing doesn't work for me either. I guess I can try
the stuff mentioned earlier, but just wanted to at least chime in with
a "yeah happens to me too" and hope we can figure this out...

jack
Posted by Jared (Guest)
on 28.11.2007 21:27
(Received via mailing list)
Jack,

While it's not an answer, my best workaround was to move away from
controllers that would have namespace conflicts, so my
Worker::EventsController is now Worker::JobsController.

I suspect the problem comes from having the controllers in different
'levels' of namespace... EventsController was at the root, and
Worker::EventsController was in a namespace.  The problem seemed to
come from the latter 'losing' it's namespace.  Where, if I had them
each in a namespace, I suspect I wouldn't see the problem.  So, maybe
there's something in Rails routing or in mongrel that's asking for
controller_name and not getting the module prepended on it?

On Nov 25, 5:14 pm, "jack.demp...@gmail.com" <jack.demp...@gmail.com>
Posted by Jared (Guest)
on 29.11.2007 15:02
(Received via mailing list)
Continuing my own thought, a quick look at the controller_path() class
method in Rails 2.0 RC1 reveals this:

in action_pack/lib/action_controller/base.rb:

class <<self
  def controller_path
    @controller_path ||= name.gsub(/Controller$/, '').underscore
  end
end

I wonder if there's a caching issue where that @controller_path ||= is
concerned?
Posted by James Herdman (biocsnerd)
on 09.12.2007 20:33
Jared wrote:
> Continuing my own thought, a quick look at the controller_path() class
> method in Rails 2.0 RC1 reveals this:
> 
> in action_pack/lib/action_controller/base.rb:
> 
> class <<self
>   def controller_path
>     @controller_path ||= name.gsub(/Controller$/, '').underscore
>   end
> end
> 
> I wonder if there's a caching issue where that @controller_path ||= is
> concerned?

Oh, I bet you're right.  I"m getting bit by the same issue right now.  I 
have two types of namespaced controller: admin and school.  The admin 
namespace has no issues, but the school namespaced controllers 
completely blow up _only_ when running "rake test:functionals", not when 
running their tests by themselves.
Posted by Thijs Cadier (Guest)
on 09.01.2008 15:40
(Received via mailing list)
Did anybody learn anything new about this issue? I'm still having
issues with Rails 2.0.2 and I'm kind of lost on what the cause is.


On Dec 9 2007, 8:33 pm, James Herdman <rails-mailing-l...@andreas-
Posted by Joseph Wilk (joesniff)
on 28.04.2008 12:13
Thijs Cadier wrote:
> Did anybody learn anything new about this issue? I'm still having
> issues with Rails 2.0.2 and I'm kind of lost on what the cause is.
> 
> 
> On Dec 9 2007, 8:33 pm, James Herdman <rails-mailing-l...@andreas-


I'm also getting this problem with Rails 2.0.2. I've noticed that I can 
make the problem go away by turning off cache_classes in the 
configuration.

config.cache_classes = false

With it on My controllers Admin::PageController & PageController often 
get muddled causing all my tests to explode :(

I guess that leans further towards this being an issue of caching and 
not respecting namespaces...

--
Joseph Wilk
http://www.joesniff.co.uk
Posted by Jared Moody (jaredmoody)
on 02.05.2008 00:37
This link was helpful for me:

http://peat.wordpress.com/2006/06/30/watch-your-namespace/

Do you also have a model with the same name as your namespace? I did. 
Seems like this should have been fixed by rails 2.0.2, but it looks like 
it's happening again