I've added ActionText into my Rails 5.2 app, according to this tutorial. I performed installation, migration and added action_text_rich_texts column. I also updated my model:
class LiveEvent < ApplicationRecord
has_rich_text :description_long
end
However has_rich_text helper seems to not working. When I try to initialize new record this way:
@live_event = LiveEvent.new(live_event_params)
description_long attribute returns nil because of this helper. Which crashes my app due to the validation constrains.
Strong param permission for description_long it's also not a case since that attribute was permitted before. This error occurs even if I want to add new record directly through the Rails console:
le = LiveEvent.new(description_long: 'test')
le[:description_long] // returns nil
Maybe there is no established binding between action_text_rich_texts and my LiveEvent model? I'm not sure what it the possible cause of this error. How can I fix it?
ActionText
is providing polymorphic association with Model we mentionhas_rich_text
.So when we define
has_rich_text
is actually we are defining an association, like we dohas_one
, 'has_many',belongs_to
.So when you write
It will create a new instance of
ActionText::RichText
model and assign the"text"
in the body column as instance ofActionText::Content
. So what ever value we assigned todescription_long
as rich text will automatically wrapped into into a div tag<div class="trix-content">
.Here is the example.
so
content
in this example is not actually a column but it's a association. same waydescription_long
in your example is anassociation
not a column.Please fine the note below "Note: you don't need to add a content field to your messages table." here in this guide https://edgeguides.rubyonrails.org/action_text_overview.html