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?
ActionTextis providing polymorphic association with Model we mentionhas_rich_text.So when we define
has_rich_textis 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::RichTextmodel and assign the"text"in the body column as instance ofActionText::Content. So what ever value we assigned todescription_longas rich text will automatically wrapped into into a div tag<div class="trix-content">.Here is the example.
so
contentin this example is not actually a column but it's a association. same waydescription_longin your example is anassociationnot 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