1
class User << ApplicatinRecord
  has_rich_text :journal
  
  def receive_sms(sms_body)
    journal.update(body:  journal.body + sms_body
  end
end

this function to append a message to the end of the ActionText is not working... something about how journal is serialized with an ActionContent class.

Blair Anderson
  • 19,463
  • 8
  • 77
  • 114

1 Answers1

1

I figured this out...

text_to_append = "some awesome string"
body = user.journal.to_trix_html # can be nil or ActionContent
user.journal.update(
  body: "#{body}<br/><div>#{text_to_append}</div>"
)

action content can be nil, so you cannot use + or += with actiontext.

You must print as html (to keep any user formatting), then append your text as new html.

Blair Anderson
  • 19,463
  • 8
  • 77
  • 114