rails caching: expire_action in another namespace

后端 未结 2 1617
悲哀的现实
悲哀的现实 2020-12-08 06:11

My application is using a namespace for administrative purposes. I recently tried to start using action caching however I ran into some problems trying to expire the cache u

相关标签:
2条回答
  • 2020-12-08 06:25

    One additional note I learned, if you want to expire a specific format, such as XML, JSON, etc., just

    expire_action(:controller => '/newsposts', :action => 'index', :format => 'xml') 
    

    or whatever format you want. It look me a while to figure out.

    0 讨论(0)
  • 2020-12-08 06:32

    after some more digging I finally found the solution. It's a bit hinted in the url_for method:

    In particular, a leading slash ensures no namespace is assumed. Thus, while url_for :controller => 'users' may resolve to Admin::UsersController if the current controller lives under that module, url_for :controller => '/users' ensures you link to ::UsersController no matter what.

    So basically,

    expire_action(:controller => '/newsposts', :action => 'index')
    

    Will expire in the default namespace, and

    expire_action(:controller => 'admin/newsposts', :action => 'index')
    

    in the admin namespace (when in default).

    RailsCast

    0 讨论(0)
提交回复
热议问题