我已经将项目升级到Rails6(v6.0.1),现在在模型中使用了Action Text。但是,我找不到一种方法来更改Ransack以便能够从内容中搜索文本,据我了解,在迁移操作文本之后,该文本现在存储在表body
的属性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
答案 0 :(得分:0)
<%= text_field_tag "topic[content_body_cont]" %>