我开始创建一个在我的rails应用程序的控制器中具有共享功能的模块。我试图在另一个需要该记录的控制器中包含记录查找。我使用友好id来强制执行corp_page的实例,试图找到控制器给我这个错误的corp_pages记录,
ActiveRecord::RecordNotFound at /admin/corporate_pages/home/corporate_panels
Couldn't find CorporatePage without an ID
代码,
module CorporateConcern
extend ActiveSupport::Concern
included do
before_filter :get_corp_page
before_filter :get_corp_panel
end
def get_corp_page
@corp_page = CorporatePage.friendly.find(params[:id])
end
def get_corp_panel
@corp_panel = CorporatePanel.where(id: params[:id]).first
end
end
class Admin::CorporatePanelsController < AdminController
include CorporateConcern
......
end
class Admin::CorporatePagesController < AdminController
include CorporateConcern
end
提前致谢