我正在努力从3.x版本4.0升级Ransack,其中允许的Ransackable属性应该被明确定义,我已经修复了所有的项目模型,但现在它在Rails核心模块上失败了.
# RuntimeError:
# Ransack needs ActionText::RichText attributes explicitly allowlisted as
# searchable. Define a `ransackable_attributes` class method in your `ActionText::RichText`
# 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 ActionText::RichText < ApplicationRecord
#
# # ...
#
# def self.ransackable_attributes(auth_object = nil)
# ["body", "created_at", "id", "locale", "name", "record_id", "record_type", "updated_at"]
# end
#
# # ...
#
# end
# ```
我已经try 在源代码中直接重新打开类,但这些更改没有被Rails获取和忽略.我试图在初始化期间找到一些配置更改,但这也不起作用.我打赌有人已经解决了从3.0到4.x的迁移问题
已经测试过的内容
- 创建低于
app/models/action_text/rich_text.rb
的模型文件
class ActionText::RichText < ApplicationRecord
# ...
def self.ransackable_attributes(auth_object = nil)
["body", "created_at", "id", "locale", "name", "record_id", "record_type", "updated_at"]
end
# ...
end
结果-&>只是忽略了,相同的问题Rails看不到这些更改.
- 更新
config/initializers/action_text.rb
以下的初始值设定项
class ActionText::RichText < ActiveRecord::Base
def self.ransackable_attributes(auth_object = nil)
["body", "created_at", "id", "locale", "name", "record_id", "record_type", "updated_at"]
end
end
初始化加载过程中出现结果错误->;
An error occurred while loading rails_helper.
Failure/Error: require File.expand_path('../config/environment', __dir__)
NoMethodError:
undefined method `has_many_attached' for ActionText::RichText:Class
# ./config/initializers/action_text.rb:7:in `<main>'
# ./config/environment.rb:5:in `<top (required)>'
# ./spec/rails_helper.rb:6:in `require'
# ./spec/rails_helper.rb:6:in `<top (required)>'
No examples found.