LoginSignup
2
1

More than 3 years have passed since last update.

Rails6 のAction Textで保存したリッチテキストを文字列で読み出す

Last updated at Posted at 2019-09-08

試しに下記の形でUserモデルにフィールドを追加したprofileで参照するリッチテキストを文字列で読み出してみる。

models/user.rb
class User < ApplicationRecord
  has_rich_text :profile
end

スクリーンショット 2019-09-09 5.53.50.png

読み出す

$ rails c
pry(main)> User.last.profile.body.to_plain_text
=> "hogeほげ\n[8664c643-550521.png]fugaふが"

太字や斜体などの装飾情報は別に保存されているみたいだが、それ以外の情報については読み出せた。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1