2

I have upgraded my app to rails 5.2 and inclined to use ActionText since old trix-editor/gem is no longer working. Now new posts display their "descriptions" but how can I display my old posts' DESCRIPTIONS with the new installed ActionText?

post.rb has_rich_text :description

posts_controller.rb ...params.require(:post).permit(:description)

_form.html.erb <%= f.rich_text_area :description %>

show.html.erb <%= @post.description %>

Descriptions are only fetching from new records in ActionText but not displaying from existing "description" columns for old posts

4

2 回答 2

1

我有一个类似的问题,我在 rails repo 或任何地方都找不到干净的解决方案。作为一种解决方法,在您的情况下,我会尝试:

显示.html.erb:。
<%= @post.try(:description).body || @post[:description] %>

这不会解决问题,但它会帮助您填充旧的帖子值。

于 2019-08-16T15:17:21.410 回答
0

这个答案对我有用。它还具有清理用于普通(非富)文本内容的表的数据库的额外好处。

“假设你的模型中有一个‘内容’,这就是你想要迁移的内容,首先,添加到你的模型中:”

has_rich_text :content

“然后创建迁移”

rails g migration MigratePostContentToActionText
class MigratePostContentToActionText < ActiveRecord::Migration[6.0]
  include ActionView::Helpers::TextHelper
  def change
    rename_column :posts, :content, :content_old
    Post.all.each do |post|
      post.update_attribute(:content, simple_format(post.content_old))
    end
    remove_column :posts, :content_old
  end
end

您可以在这里找到我使用的原始解决方案 https://github.com/rails/rails/issues/35002#issuecomment-562311492

于 2020-10-21T05:04:49.197 回答