Nag*_*iHW 6 ruby ruby-on-rails-3 activeadmin
我正在使用ruby 3.1.3,rails 7.0.5和activeadmin 3.0.
我只是按照activeadmin 网站的安装说明进行操作,但出现以下错误:
ActionView::Template::Error (Ransack needs AdminUser attributes explicitly allowlisted as
searchable. Define a `ransackable_attributes` class method in your `AdminUser`
model, watching out for items you DON'T want searchable (for
example, `encrypted_password`, `password_reset_token`, `owner` or
other sensitive information). You can use the following as a base:
ruby
class AdminUser < ApplicationRecord
# ...
def self.ransackable_attributes(auth_object = nil)
["created_at", "email", "encrypted_password", "id", "remember_created_at", "reset_password_sent_at", "reset_password_token", "updated_at"]
end
# ...
end
):
1: # frozen_string_literal: true
2: insert_tag renderer_for(:index)
Run Code Online (Sandbox Code Playgroud)
我尝试按照说明进行操作,但出现了相同的错误,但现在函数内部的数组为空。
刚刚从 active_admin 2.x 升级到 3.0 时遇到了同样的问题。
新版本使用新版本的 ransack (v4),其中包含一项重大更改,因为它现在要求您在模型中显式声明允许的属性和关联列表以进行搜索(此处的更改日志)。
将模型中的所有属性列入白名单ApplicationRecord将使您的应用程序再次运行:
class ApplicationRecord < ActiveRecord::Base
# ...
def self.ransackable_attributes(auth_object = nil)
authorizable_ransackable_attributes
end
def self.ransackable_associations(auth_object = nil)
authorizable_ransackable_associations
end
end
Run Code Online (Sandbox Code Playgroud)
但您可能希望为代码库上的每个特定模型自定义这些列表。