Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
FreeApophis opened this issue Apr 5, 2017 · 29 comments

Comments

@FreeApophis
Copy link

FreeApophis commented Apr 5, 2017

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

@nikolaokonesh
Copy link

nikolaokonesh commented Apr 8, 2017

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!!!!

@markrebec
Copy link

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.

@chriswnl
Copy link

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

@markrebec
Copy link

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.

@ericcf
Copy link

ericcf commented May 24, 2017

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.

@turboladen
Copy link

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.

@thanhtruong1216
Copy link

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

@legacy370
Copy link

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.

@stale
Copy link

stale bot commented Dec 4, 2018

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 stale bot added the wontfix label Dec 4, 2018
@stale stale bot closed this as completed Dec 12, 2018
@feliperaul
Copy link
Contributor

Still facing this on Rails 5.2.2 and gem version 4.2.4

@FreeApophis
Copy link
Author

This project is obviously dead...

@feliperaul
Copy link
Contributor

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

@FreeApophis
Copy link
Author

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.

@patricklindsay
Copy link
Collaborator

What is dead may never die...

@stale stale bot removed the wontfix label Dec 28, 2018
@hainminsoe
Copy link

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

@mr-morkou
Copy link

mr-morkou commented Mar 26, 2019

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

@stale
Copy link

stale bot commented May 26, 2019

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 stale bot added the wontfix label May 26, 2019
@FreeApophis
Copy link
Author

ping

@stale stale bot removed the wontfix label May 28, 2019
@stale
Copy link

stale bot commented Sep 7, 2019

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 stale bot added the wontfix label Sep 7, 2019
@FreeApophis
Copy link
Author

nope still not stale, just no maintainer.

@stale stale bot removed the wontfix label Sep 11, 2019
@stale
Copy link

stale bot commented Nov 10, 2019

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 stale bot added the wontfix label Nov 10, 2019
@FreeApophis
Copy link
Author

I am about to write an unstale bot...

@stale stale bot removed the wontfix label Nov 12, 2019
@stale
Copy link

stale bot commented Jan 11, 2020

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 stale bot added the wontfix label Jan 11, 2020
@FreeApophis
Copy link
Author

nope...

@stale stale bot removed the wontfix label Jan 12, 2020
@stale
Copy link

stale bot commented Mar 12, 2020

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 stale bot added the wontfix label Mar 12, 2020
@FreeApophis
Copy link
Author

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

@FreeApophis FreeApophis reopened this Mar 13, 2020
@stale stale bot removed the wontfix label Mar 13, 2020
@stale
Copy link

stale bot commented May 13, 2020

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 stale bot added the wontfix label May 13, 2020
@patricklindsay
Copy link
Collaborator

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.

@coppolaf
Copy link

coppolaf commented Nov 1, 2023

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests