An issue with Rails ActionText with Rails_Admin
I just started using Rails 7 Action Text and I was pleasantly surprised with rich text editor. Not only it's easy to install but also it comes with many features out of the box.
- You can upload images and files without touching ActiveStorage
- You can attach the rich_text content into any model you have
In general, you will not find any issues with ActionText, unless if you want to use it with Rails_admin.
You will receive an error when you try to access the model that contains a rich_text element in the Rails_admin.
For now, this is a quick fix:
Change the file app/views/active_storage/blobs/_blob.html.erb :
Swap the image that you have there to:
<%= image_tag polymorphic_url(blob.representation(resize_to_limit: local_assigns[:in_gallery] ? [ 800, 600 ] : [ 1024, 768 ]), script_name: nil) %>
Then you have to add a variable into the "if blob.representable?" like this:
<% if blob.representable? && @not_rails_admin %>
Finally go to app/controllers/application_controller.rb :
def not_rails_admin @not_rails_admin = true end
Add the method above.
Then go to your posts_controller.rb or any other controller and add:
The idea is to tell Rails that when you are not running Rails_admin, you should run the blurb code. If it detects that it is running Rails_admin, it should not display the blurb that gives the error.