Porter Bayne

Joined

1,050 Experience
10 Lessons Completed
0 Questions Solved

Activity

This was so helpful.

I was able to override the default actiontext HTML templates after viewing this. My current codebase's ActionText install does not have any editable ERB files in /views/, and I couldn't figure out a way to get an installer to generate them.

I made this initializer and custom ERB templates, and it works for me! I can now point ActionText to load inside a custom div (in my case, one without the trix-content CSS class.)

Thanks x 1,000 Chris.

# config/initializers/action_text.rb
module ActionTextLoadCustomPartial
  def to_rendered_html_with_layout
    # this points to app/views/layouts/custom_action_text/contents/_content.html.erb:
    render layout: "/custom_action_text/contents/content", partial: to_partial_path, formats: :html, locals: { content: self }
  end

  def to_partial_path
    # this points to app/views/custom_action_text/contents/_content.html.erb:
    "/custom_action_text/contents/content"
  end
end

ActiveSupport.on_load :action_text_content do
  self.prepend ActionTextLoadCustomPartial
end

Here's the layout file:

<div class="rich-text-content-layout">
  <%= yield -%>
</div>

IMPORTANT: Here's the partial file:

<div class="rich-text-content">
  <%= render_action_text_content(content) %>
</div>

That render_action_text_content(content) is necessary to output the rich text, I assume b/c it's defined in locals: {} above in the layout call. I found that poking around in https://github.com/rails/rails/tree/main/actiontext

Posted in Realtime Nested Comments: Part 2 Discussion

Any further thought on this? I'm wondering the same thing.

Posted in Realtime Nested Comments: Part 3 Discussion

Sean, thanks. I had the same issue and you saved me a ton of time!

Posted in Realtime Nested Comments: Part 3 Discussion

Marc, thank you. This seems to work well for me and saved me hours of time, no doubt.

Posted in Realtime Nested Comments: Part 2 Discussion

Was it b/c in that video, one user is looking at the page in one browser? So it's updating for that person's session, but not broadcast out to other users simultaneously. Been awhile since I've seen that Twitter clone vid but I'm guessing that's why.

logo Created with Sketch.

Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

© 2022 GoRails, LLC. All rights reserved.