Ruby on rails - Devise 使用应用程序的布局,但忽略 ApplicationController 方法和过滤器



设计使用宿主应用程序的布局,但不使用ApplicationController中指定的控制器方法和before_过滤器。我得到一个错误,暗示@sitemap是nil在我的布局的这一部分:<%= select_tag :site_navigation, options_for_select(@sitemap), prompt: "Quick Navigation" %>


经理/application_controller.rb

module Manager
    class ApplicationController < ActionController::Base
        protect_from_forgery
        before_filter :load_sitemap
        ... more code here ...

    protected
        # This is run every time a request is made...but
        # it doesn't get run by Devise's SessionsController
        # even though Devise uses the layout which uses
        # @sitemap and fails if it is nil
        def load_sitemap
            return [] unless Manager.configuration.master?
            @sitemap = {
                "Albums" => albums_path,
                "Add Wine Award" => new_award_path,
                "Businesses" => businesses_path,
                "Cash Tracking" => cash_trackers_path,
                "Events" => events_path,
                "Locations" => locations_path,
                "Medals" => medals_path,
                "New Timesheet" => new_timesheet_path,
                "Recipes" => recipes_path,
                "Reviews" => reviews_path,
                "Wines" => wines_path,
                "Wine Competitions" => competitions_path
            }
        end
    end
end

这可能是基于您使用Manager模块的名称间距问题。

设计的user_controller将继承ApplicationController。非Manager::ApplicationController

如果你想让设计运行你的before过滤器,你需要把它放到根级的ApplicatonController中。

相关内容

  • 没有找到相关文章

最新更新