【问题标题】:How to extend refinerycms controller with decorators?如何使用装饰器扩展refinerycms 控制器?
【发布时间】:2014-08-13 12:24:20
【问题描述】:

我生成了一个名为 Doctors 的扩展。

我正在尝试使用以下指南 http://refinerycms.com/guides/extending-controllers-and-models-with-decorators 使用装饰器扩展默认功能。

装饰者:

Refinery::PagesController.class_eval do

    before_filter :find_doctors, only: [:doctors]

    protected

    def find_doctors
      @find_doctors = Refinery::Doctors::Doctor.all
    end      

end                                                

如果我将 [:doctors] 替换为 [:home],我可以在主页中看到对象,但我想在 Doctor index 视图中显示这些项目。

我错过了什么?

【问题讨论】:

    标签: refinerycms


    【解决方案1】:

    使用您的代码,您尝试在 Refinery::PagesController 中的“doctors”操作之前运行“find_doctors”方法,但是Refinery::PagesController 中不存在操作“doctors”。

    替换 [:home] 而不是 [:doctors] 适用于主页,因为 Refinery::PagesController 中确实存在操作“home”。

    所以,你需要做的是装饰 Refinery::DoctorsController 而不是 Refinery::PagesController 并在 index 之前运行 find_doctors 方法索引视图。

    Refinery::DoctorsController.class_eval do
    
       before_filter :find_doctors, only: [:index]
    
       protected
    
       def find_doctors
         @find_doctors = Refinery::Doctors::Doctor.all
       end
    end      
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-18
      • 1970-01-01
      • 2021-07-07
      • 2017-03-06
      • 1970-01-01
      • 1970-01-01
      • 2019-07-20
      • 2016-03-30
      相关资源
      最近更新 更多