Devise使用app的布局但忽略了ApplicationController方法和过滤器

时间:2014-03-25 03:40:22

标签: ruby-on-rails ruby ruby-on-rails-4 devise

Devise正在使用主机应用程序的布局,但没有使用ApplicationController中指定的控制器方法和before_过滤器。我得到一个错误,暗示@sitemap在我的布局的这一部分中为零:<%= 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

1 个答案:

答案 0 :(得分:1)

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

设计user_controller将继承自ApplicationController。 不是Manager::ApplicationController

如果您想要设计运行之前的过滤器,则需要将其放入根级ApplicatonController