【发布时间】:2021-10-28 20:37:48
【问题描述】:
我需要在 Rails ActionText 字段中搜索文本。找不到任何解决方案,所以我创建了一个纯文本字段,并在提交 ActionText 表单时运行 before_ save self.content_plain_text = content.body.to_plain_text。这很好用,我可以在content_plain_text 中搜索。
但现在我需要为所有已经存在的数据更新content_plain_text。找到这个有迁移的How do I move a column (with contents) to another table in a Rails migration?。我以为我可以模仿它,但这不起作用。
class CopyContentToContentPlainText < ActiveRecord::Migration[6.0]
def up
Doc.find_each do |d|
content_plain_text = action_text_rich_texts.record_id[d].content.body.to_plain_text
Content.create!(doc_id: d.id, content_plain_text: content_plain_text)
end
end
end
我在获取 ActionText 字段时迷失了方向。 record_id对应doc_id
【问题讨论】:
标签: ruby-on-rails rails-migrations actiontext