Ruby on Rails - Active Admin 未定义方法 `except' #
Ruby on Rails - Active Admin undefined method `except' for #
当我在 application_controller.rb 中输入一些代码时,Active Admin 出现错误。错误是(当我尝试在活动管理员中访问 HomeConfig 时):
undefined method 'except' for #<HomeConfig:0x007f8877cfda58>
在这种情况下,当我将此代码放入application_controller.rb时会发生错误:
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
# Code that cause the problem
before_filter :contact_info, :home_config
def contact_info
@contact_infos = ContactInfo.all
end
def home_config
@home_configs = HomeConfig.last
end
end
终端错误日志:
Started GET "/alumni/admin/home_configs" for 127.0.0.1 at 2018-10-02 09:07:38 -0300
Processing by Admin::HomeConfigsController#index as HTML
HomeConfig Load (0.4ms) SELECT `home_configs`.* FROM `home_configs` ORDER BY `home_configs`.`id` DESC LIMIT 1
AdminUser Load (0.3ms) SELECT `admin_users`.* FROM `admin_users` WHERE `admin_users`.`id` = 1 ORDER BY `admin_users`.`id` ASC LIMIT 1
Rendered /Users/Atua/.rvm/gems/ruby-2.1.3@facensAlumni/bundler/gems/activeadmin-dce083189c46/app/views/active_admin/resource/index.html.arb (598.9ms)
Completed 500 Internal Server Error in 644ms
NoMethodError - undefined method `except' for #<HomeConfig:0x007f887c002d58>:
Started POST "/__better_errors/32ad65699eb25cf6/variables" for 127.0.0.1 at 2018-10-02 09:07:39 -0300
ContactInfo Load (0.3ms) SELECT `contact_infos`.* FROM `contact_infos`
如果我撤销此代码并重新启动服务器,一切正常。有人知道发生了什么事吗?
谢谢。
@home_configs = HomeConfig.last
这是造成错误的原因。 ActiveAdmin
期望 @home_configs
是一个数组。而你的代码 HomeConfig.last
returns 只有最后一个 HomeConfig.
您需要将 HomeConfig.last
更改为:HomeConfig.all
。
试用并反馈。
当我在 application_controller.rb 中输入一些代码时,Active Admin 出现错误。错误是(当我尝试在活动管理员中访问 HomeConfig 时):
undefined method 'except' for #<HomeConfig:0x007f8877cfda58>
在这种情况下,当我将此代码放入application_controller.rb时会发生错误:
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
# Code that cause the problem
before_filter :contact_info, :home_config
def contact_info
@contact_infos = ContactInfo.all
end
def home_config
@home_configs = HomeConfig.last
end
end
终端错误日志:
Started GET "/alumni/admin/home_configs" for 127.0.0.1 at 2018-10-02 09:07:38 -0300
Processing by Admin::HomeConfigsController#index as HTML
HomeConfig Load (0.4ms) SELECT `home_configs`.* FROM `home_configs` ORDER BY `home_configs`.`id` DESC LIMIT 1
AdminUser Load (0.3ms) SELECT `admin_users`.* FROM `admin_users` WHERE `admin_users`.`id` = 1 ORDER BY `admin_users`.`id` ASC LIMIT 1
Rendered /Users/Atua/.rvm/gems/ruby-2.1.3@facensAlumni/bundler/gems/activeadmin-dce083189c46/app/views/active_admin/resource/index.html.arb (598.9ms)
Completed 500 Internal Server Error in 644ms
NoMethodError - undefined method `except' for #<HomeConfig:0x007f887c002d58>:
Started POST "/__better_errors/32ad65699eb25cf6/variables" for 127.0.0.1 at 2018-10-02 09:07:39 -0300
ContactInfo Load (0.3ms) SELECT `contact_infos`.* FROM `contact_infos`
如果我撤销此代码并重新启动服务器,一切正常。有人知道发生了什么事吗?
谢谢。
@home_configs = HomeConfig.last
这是造成错误的原因。 ActiveAdmin
期望 @home_configs
是一个数组。而你的代码 HomeConfig.last
returns 只有最后一个 HomeConfig.
您需要将 HomeConfig.last
更改为:HomeConfig.all
。
试用并反馈。