Ask A Question


You’re not receiving notifications from this thread.

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.



Maybe it's length:


Hi Greg, thanks for that. Once updated, that throws up a 'NoMethodError in BlogPosts#index' error.


After a bit more playing around, managed to solve it. Thanks again @Greg S.


you can do
<%= truncate(blog_post.content.to_plain_text, length: 130) %>


In my case, I can upload images but they fail afterwards. Something about vips


You're probably running into the issue listed in

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=""></script>

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.

# change this
<% if blob.representable? %>
# to
<% if %>
  <video controls="true" width="100%" preload="metadata">
    <source src="<%= rails_blob_url(blob) %>" type="<%= blob.content_type %>"></source>
<% elsif blob.representable? %>


# 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"
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 83,168+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.