我已将我的项目升级到 Rails6 (v6.0.1),现在在我的模型中使用 Action Text。但是我找不到改变我的 Ransack 以便能够从内容中搜索文本的方法,我知道在 Action Text 迁移之后它现在存储在body
table 的属性中action_text_rich_texts
。有人会有好的建议吗?
错误信息:
undefined method `content_body_cont' for Ransack::Search<class: Topic, base: Grouping <combinator: and>>:Ransack::Search
下面是我的代码的摘录。
模型:
class Topic < ApplicationRecord
has_rich_text :content
控制器:
class TopicsController < ApplicationController
def index
@search = Topic.ransack(params[:q])
@topics = @search.result
end
end
看法:
<%= search_form_for(@search, url: topics_path, html: {method: :get, role: 'form'}) do |f| %>
<%= f.text_field :content_body_cont %>
架构文件:
create_table "action_text_rich_texts", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC", force: :cascade do |t|
t.string "name", null: false
t.text "body", size: :long
t.string "record_type", null: false
t.bigint "record_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["record_type", "record_id", "name"], name: "index_action_text_rich_texts_uniqueness", unique: true
end