Skip to content

Can't save model with associated ActionText with image #3386

@tosbourn

Description

@tosbourn

Having followed the guidance to enable ActIonText within Rails Admin I'm still getting an error when saving content that has an image.

Error message: undefined method 'to_model' for #<ActiveStorage::VariantWithRecord:0x00007f9499bf30d0>

This is being thrown in my _blob partial;

  <% if blob.representable? %>
    <picture>
      <source srcset="<%= polymorphic_url(blob.representation(resize_to_limit: local_assigns[:in_gallery] ? [ 800, 600 ] : [ 1024, 768 ], format: :webp), script_name: nil) %>" type="image/webp" />
      <%= image_tag polymorphic_url(blob.representation(resize_to_limit: local_assigns[:in_gallery] ? [ 800, 600 ] : [ 1024, 768 ]), script_name: nil), alt: (blob.caption ? blob.caption : blob.filename), class: "mx-auto rounded-lg", loading: 'lazy' %>
    </picture>
  <% end %>

You'll note I've already applied the polymorphic_url patch as suggested, in the wiki article.

What I also found odd is if you remove the ActionText content (so the form doesn't have anything to do with ActionText) the error still happens, even though in the payload I can see my content would not have been submitted by the form.

Notes

related model:

class Article < ApplicationRecord
  include ArticleAdmin
  has_rich_text :content
  ...
end

related rails_admin config:

module ArticleAdmin
  extend ActiveSupport::Concern

  included do
    rails_admin do
      list do
        ...
      end

      edit do
        field :approved
        field :title
        field :content
        field :categories
      end
    end
  end
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions