ckeditor icon indicating copy to clipboard operation
ckeditor copied to clipboard

Invalid single-table inheritance type: Ckeditor::Picture is not a subclass of Ckeditor::Picture

Open FreeApophis opened this issue 7 years ago • 29 comments

This is a duplicate of Bug #680 which was closed by the author, but the Bug is real and still in the current stable release.

The Column Name type (not sure if *_type as well) is reserved for polymorphic associations, thats why Rails is complaining (sometimes). Maybe the bug only appears when you actually use polymorphic associations on other models.

Please rename at least the following column: "type" And it would probably better to rename "data_content_type" unless it is used for a polymorphic associations, which I could not test, because it crashes before any data can be saved in that column.

See: http://stackoverflow.com/questions/20357997/invalid-single-table-inheritance-type-rails Or: https://www.ruby-forum.com/topic/103871

FreeApophis avatar Apr 05 '17 18:04 FreeApophis

Rails 5.1 undefined method to_param' for #ActionController::Parameters:0x007fa1f500e328 Did you mean? to_yaml`

add .to_i for pictures_controller.rb @pictures = Ckeditor::Paginatable.new(@pictures).page params[:page].to_i

also Invalid single-table inheritance type: Ckeditor::Picture is not a subclass of Ckeditor::Picture

Help!!!!

nikolaokonesh avatar Apr 08 '17 01:04 nikolaokonesh

I stumbled across this while researching the same problem in a personal project I'm working on. The source of the problem seems to be code reloading (specifically constant reloading?) in development mode, as hinted at in the previously closed issue with the reproduction steps. When you edit one of these models and re-run something in a console or refresh a web request without restarting the console/webserver, you'll bump into this issue. In my case I'm also using spring, and the problem doesn't go away until I spring stop then re-run a console.

Unfortunately I have no idea what the actual source of the problem is. Someone I spoke with recently suggested using require_dependency explicitly for the models that are having this problem, which I'm going to try in my own project. Thought I'd chime in just in case it's helpful.

markrebec avatar Apr 14 '17 23:04 markrebec

I was experiencing this today on STI inheritance. Adding 'unloadable' to the inheriting class fixed it for me.

chriswnl avatar May 22 '17 23:05 chriswnl

Apologies for chiming in again even though I'm not using ckeditor, and my problem is unrelated 😸 but I actually recently managed to (sorta) track down the root of the problem here.

It seems that (some? all?) class constants are being undefined/redefined somewhere during the code reloading process in a rails development environment, after which the actual ruby objects stored in those class constants are no longer equal. That means the following line fails due to inequality: https://github.com/rails/rails/blob/master/activerecord/lib/active_record/inheritance.rb#L202

If I monkeypatch that line to read unless subclass.name == self.name || descendants.include?(subclass) suddenly everything works as expected. I'm really not sure whether the fix ought to be something similar to my monkeypatch in activerecord, or if it should be fixed somewhere in the way rails' code reloading works in 5.x.

markrebec avatar May 23 '17 00:05 markrebec

Another way to fix this is to add the following to the generated Ckeditor::Picture class:

self.inheritance_column = nil

which tells Rails to ignore the type column with respect to STI.

ericcf avatar May 24 '17 16:05 ericcf

I'm also not using ckeditor, but ran across this looking for some explanation for my problem (I'm not trying to use type for something). Thanks for the research and explanation, @markrebec.

turboladen avatar Jun 30 '17 18:06 turboladen

I also have this issue. And the error is miss leading because there was another error happen before that when I check rails log. Here is my fix: https://stackoverflow.com/a/50767069/9516571

thanhtruong1216 avatar Jun 08 '18 19:06 thanhtruong1216

Similar to the answer from ericcf, I put into

class Ckeditor::Picture < Ckeditor::Asset def self.inheritance_column nil end I did have to restart localhost, but then I could upload pictures repeatedly with no errors.

legacy370 avatar Jul 08 '18 19:07 legacy370

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Dec 04 '18 12:12 stale[bot]

Still facing this on Rails 5.2.2 and gem version 4.2.4

feliperaul avatar Dec 23 '18 12:12 feliperaul

This project is obviously dead...

FreeApophis avatar Dec 23 '18 20:12 FreeApophis

@FreeApophis last commit was 19 days ago, has a low number of issues opened, has comments on recent issues opened ... it's not dead.

feliperaul avatar Dec 23 '18 20:12 feliperaul

The Issue count is only low because they closed hundreds of bugs like this one with the stale bot. The Commit 19 days ago was only to include the stale bot. The last commit before that one was in March. This project is dead.

FreeApophis avatar Dec 24 '18 09:12 FreeApophis

What is dead may never die...

patricklindsay avatar Dec 28 '18 02:12 patricklindsay

I was also face same issue, updating my gems everything is OK right now, hope this help.

hainminsoe avatar Feb 18 '19 10:02 hainminsoe

type keyword is a reserved word for ActiveRecord. Need column type rename. https://en.wikibooks.org/wiki/Ruby_on_Rails/ActiveRecord/Naming

mr-morkou avatar Mar 26 '19 12:03 mr-morkou

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar May 26 '19 11:05 stale[bot]

ping

FreeApophis avatar May 28 '19 14:05 FreeApophis

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Sep 07 '19 13:09 stale[bot]

nope still not stale, just no maintainer.

FreeApophis avatar Sep 11 '19 17:09 FreeApophis

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Nov 10 '19 18:11 stale[bot]

I am about to write an unstale bot...

FreeApophis avatar Nov 12 '19 10:11 FreeApophis

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jan 11 '20 10:01 stale[bot]

nope...

FreeApophis avatar Jan 12 '20 11:01 FreeApophis

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Mar 12 '20 12:03 stale[bot]

I dont care if the project is dead, this ticket stays open

FreeApophis avatar Mar 13 '20 10:03 FreeApophis

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar May 13 '20 03:05 stale[bot]

Just checked, this is still an issue in development environment only as it is caused by code reloading (which is also why it doesn't always happen - see Rails issue).

If you encounter the issue a manual stop/start of your server should resolve it.

I've had a look but can't find the root cause, the type column is used for STI so adding inheritance_column unfortunately isn't the solution.

Pinning to prevent the stale bot from closing.

patricklindsay avatar May 15 '20 22:05 patricklindsay

Not sure if able to reliably reproduce, but this seems to be working for me. Renamed column and just aliased in the one model file. rails (5.2.1), ckeditor (4.2.4)

  1. renamed "type" to "model" in my created migration. Rename column if your system is live already, instead.
class CreateCkeditorAssets < ActiveRecord::Migration[5.2]
  def self.up
    create_table :ckeditor_assets do |t|
      t.string  :data_file_name, null: false
      t.string  :data_content_type
      t.integer :data_file_size
      t.string  :data_fingerprint
      t.string  :model, limit: 30 
# Line above for for t.string  :type, limit: 30 turned to :model
  1. in generated model Ckeditor::Asset
class Ckeditor::Asset < ActiveRecord::Base
  include Ckeditor::Orm::ActiveRecord::AssetBase
  include Ckeditor::Backend::Paperclip

  # add this line
  alias_attribute :type, :model

end

Seems clean without overriding anything in the gem. Hope it works for someone else too. cc @FreeApophis

gmenel avatar Oct 16 '20 11:10 gmenel

having same issue on rails 6.1.7.3, i've done some customizations changing base path to store images and other attachments for other areas of my app, so... i've added a custom carrierwave image controller to serve ckeditor image assets preserving its original position inside app tree see code below:

#
#  controller used to manage image retrieval from CarrierWave gem
class CwImagesController < ApplicationController

   .....

  #
  #
  # serves pictures uploaded by ckeditor
  def ck_pics
    #
    # set base path to reflect archival schema outside the 'public' folder
    path = Rails.root + "uploads/ckeditor/pictures/#{params[:id].to_s}/#{params[:filename]}.#{params[:format]}"
    # sends requested image back as binary stream
    send_file( path,
      :disposition => 'inline',
      :x_sendfile => true )
    #
  end
end 

then used ericcf suggestion he's posted on may 24 2017

self.inheritance_column = nil

this 2 actions has solved my issues, now it seems be working fine!! hoping this may help someone!

coppolaf avatar Nov 01 '23 17:11 coppolaf