Admin::DashboardController#index 中的 NoMethodError

NoMethodError in Admin::DashboardController#index

我是 rails 的新手,正在使用活动管理员进行工作,每当我打开活动管理仪表板时都会收到此错误

NoMethodError in Admin::DashboardController#index
undefined method `asideSection' for #<Admin::DashboardController:0x00007fc544017d70>

这是我的 application_conrtoller.rb

class ApplicationController < ActionController::Base
    before_action :asideSection
    def hhome

    end

    def getAsideSection
        @asideSections = Page.all
    end
end

请问如何解决。

before_action :asideSection 尝试调用名为 asideSection.

的方法

此方法不存在。

但是,您已经 定义了一个名为:getAsideSection 的方法。我想这就是你想要的称呼。

因此,您可以将其更改为:before_action :getAsideSection,或将方法重命名为 asideSection

下面是我的写法,同样遵循使用 snake_case 作为变量和方法名称的 ruby style guide convention

class ApplicationController < ActionController::Base
  before_action :get_aside_sections

  def home
    # ...
  end

  private

  def get_aside_sections
    @aside_sections = Page.all
  end
end