代码之家  ›  专栏  ›  技术社区  ›  user3576036

如何在rails过滤器中给出多个if条件

  •  0
  • user3576036  · 技术社区  · 6 年前

    我正在尝试调用rails筛选器 caches_action @page

    有一个 if 条件。

    class PagesController < ApplicationController
     caches_action :listing,  if: -> { @page.present? }
    
     def listing
    
     end
    end
    

    class PagesController < ApplicationController
    
         caches_action :listing,  if: -> { @page.present? }, 
                      :if => Proc.new{ |controller| 
                            controller.do_something? and 
                            controller.some_other_thing? }
    
    
         def listing
    
         end
    end
    

    有人能告诉我给出多重if条件的正确方法吗?

    0 回复  |  直到 6 年前