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
I don't know what problem was for you, but fixed mine too! I believe I ran the same steps as the video, but the rich text field wasn't being rendered, this fixed for me, thanks
Yeah, without it, the Content rich text area is actually empty for me. and you can't do anything. The Rich text editor is not rendereed at all. I am using Ubuntu environment.
So, the script actually fixs it. It seems that the install command from rails is not doing the correct job (including the misconfigured css).
Thanks Patryk!
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
When I add "rich" to form.text_area, the content box is no longer active. i cant type into it, i cant tab into it. its just a visual piece. "bold, italics, etc" do not appear. it does not seem to work.
When uploading to Render I receive the error of "ActionView::Template::Error (The asset "actiontext.css" is not present in the asset pipeline." Note: It works in the development environment.
In case this happens to anyone else, I discovered the issue. For some reason the actiontext.css
file was categorized as an "Untracked file" per git. I had to manually add the file to stage for commit (i.e., git add <file>
). Additionally, it looks like additional Action Text and Action Storage files were all categorized as untracked (e.g., db migrations). These needed to be manually staged as well to ensure Action Text works.