Rich Text Blog Posts with ActionText Discussion
Hi Chris, thanks for the video. I was wondering how do I truncate the text on the index.html page? I only want to show 130 characters of the content (previously body).
<%= truncate(blog_post.content, :length 130) %> no longer works.
Thanks
Maybe it's length:
In my case, I can upload images but they fail afterwards. Something about vips
You're probably running into the issue listed in
edgerails
from the site -
If there's an attached resource within content field, it might not show properly unless you have libvips/libvips42 package installed locally on your machine. Check their install docs on how to get it."
To make that editor work in any way shape, or form I had to add following line to the head in the application.html.erb
<script type="text/javascript" src="https://unpkg.com/trix@2.0.0/dist/trix.umd.min.js"></script>
Helped for me too, but IDK why we should import that tag if it is loaded into js app. 0.0
To make "content" field to look good in the form without deleting "@import 'actiontext.css';" line from ../stylesheets/application.tailwind.css, you can just run this command in your rails project root directory:
rails tailwindcss:build
This command should fix update styles correctly. And if you plan to make any more changes to styles or styles files, you can run:
rails tailwindcss:watch
to update any styles changes automatically.
Hope this helps
Chris does not cover this in the video but I thought it was neat. If you want to see your video attachments actually play and not just have an image preview, you just need to modify a couple of files.
app/views/active_storage/blobs/_blob.html.erb
# change this
<% if blob.representable? %>
# to
<% if blob.video? %>
<video controls="true" width="100%" preload="metadata">
<source src="<%= rails_blob_url(blob) %>" type="<%= blob.content_type %>"></source>
</video>
<% elsif blob.representable? %>
AND
config/application.rb
# add this to inside the class
config.after_initialize do
ActionText::ContentHelper.allowed_attributes.add "style"
ActionText::ContentHelper.allowed_attributes.add "controls"
ActionText::ContentHelper.allowed_tags.add "video"
ActionText::ContentHelper.allowed_tags.add "audio"
ActionText::ContentHelper.allowed_tags.add "source"
end