This project is archived and is in readonly mode.
weird behavior on expire_page when you are running under namespace
-
Daniel Lopes
To force Rails to don't use admin in path what I did was:
expire_page :controller => "/posts", :action => "show", :only_path => true
But "/posts" is as strange for a controller name. Don't you think?
-
Andrea Campi
- Tag changed from rails3.0rc to rails3
-1 I'm not sure why do you think this is a bug; taking the namespace in consideration sounds like the only reasonable behavior to me.
-
Daniel Lopes
Andrea, I didn't said anything about the Admin namespace in the Sweeper. That is the reason why I think this is undesired. What I think is the right thing to expire the admin posts is:
expire_page :controller => 'admin/posts', :action => 'index'
But expire the admin when I want to expire the public controller, for me, is strange/
-
Andrea Campi
The
Sweeperitself may not be in theAdminnamespace, but you are assigning it to the @Admin::PostsController@; when#expire_pageis invoked, it invoked @#url_for@, which will take the controller namespace into consideration to build the cache path.
That sounds consistent to the way#url_forworks. -
Daniel Lopes
Actually I any place I reference the admin namespace in the sweeper, neither in the controllers. The sweeper will expire the Admin controller without I said to do that.
-
Andrea Campi
Your controller is named
Admin::PostsController. That's all the namespacing Rails needs to see.If that's not the case, you need to show more of your controllers, otherwise there's no way I can guess what you mean.
-
Daniel Lopes
I attached an app for the example. In the source folder I have a PostsController and an Admin::PostsController. My admin calls the cache_sweeper method and say to dispatch it in create and update.
My Sweeper observes the Post model and in the right callback it calls:
expire_page :controller => "posts", :action => "show", :only_path => true
But calling just posts in the expire_page and not admin/posts will expire admin/posts. For me it's against of the principle of least surprise. Rails inferrers that I want to expire the admin just because the controller that call cache_sweeper is in Admin namespace even when I say explicitly that the controller is just posts?
For it's a strange.
Take a look in the app attached.
-
Andrea Campi
But calling just posts in the expire_page and not admin/posts will expire admin/posts. For me it's against of the principle of least surprise. Rails inferrers that I want to expire the admin just because the controller that call cache_sweeper is in Admin namespace even when I say explicitly that the controller is just posts?
Yes, that's what I was trying to tell you, sorry if I didn't make it clear.
Personally, I don't find it confusing at all, it's exactly how I would expect it to work. For instance, that's how
link_toworks:link_to 'test', :controller => "posts", :action => "index} # <a href="/admin/posts">test</a> link_to 'test', :controller => "/posts", :action => "index} # <a href="/posts">test</a>If
expire_pageandlink_towere to build different URLs, now that would be confusing! -
Daniel Lopes
Now I got what are you trying to explain. In the context of views is pretty clear when the view that call's link_to (and uses url for behind) will take his own controller as scope for the url.
In the sweepers I don't think it's so clear that's the calling of cache_sweeper in the controller will be responsible for set the scope for the url_for. But I got what you tried to explain and looking for the point of view of a link_to you are correct.
I will close this ticket.
-
Rohit Arondekar
- State changed from new to invalid
- Importance changed from to Low
