[英]Ruby on Rails - Active Admin undefined method `except' for #
I'm getting a error in Active Admin when I put some code in my application_controller.rb. 将一些代码放入application_controller.rb中时,Active Admin中出现错误。 The error is (when i try access HomeConfig in active admin):
错误是(当我尝试在活动管理员中访问HomeConfig时):
undefined method 'except' for #<HomeConfig:0x007f8877cfda58>
In this case, the error occurs when I put this code in application_controller.rb: 在这种情况下,将以下代码放在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
And the log of error in terminal: 和终端中的错误日志:
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`
If I withdraw this code and restart the server, everything works fine. 如果我退出此代码并重新启动服务器,则一切正常。 Anyone know what happening?
有人知道发生了什么吗?
Thanks. 谢谢。
@home_configs = HomeConfig.last
This is creating the error. 这是在创建错误。
ActiveAdmin
expects @home_configs
to be an array. ActiveAdmin
希望@home_configs
是一个数组。 While your code HomeConfig.last
returns only the last HomeConfig. 虽然您的代码
HomeConfig.last
仅返回最后一个HomeConfig。
You need to change HomeConfig.last
to something like: HomeConfig.all
. 您需要将
HomeConfig.last
更改为类似: HomeConfig.all
。
Try it and feedback. 试试看并提供反馈。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.