ckeditor
ckeditor copied to clipboard
Invalid single-table inheritance type: Ckeditor::Picture is not a subclass of Ckeditor::Picture
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
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!!!!
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.
I was experiencing this today on STI inheritance. Adding 'unloadable' to the inheriting class fixed it for me.
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.
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.
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.
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
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.
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.
Still facing this on Rails 5.2.2 and gem version 4.2.4
This project is obviously dead...
@FreeApophis last commit was 19 days ago, has a low number of issues opened, has comments on recent issues opened ... it's not dead.
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.
What is dead may never die...
I was also face same issue, updating my gems everything is OK right now, hope this help.
type keyword is a reserved word for ActiveRecord. Need column type rename. https://en.wikibooks.org/wiki/Ruby_on_Rails/ActiveRecord/Naming
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.
ping
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.
nope still not stale, just no maintainer.
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.
I am about to write an unstale bot...
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.
nope...
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.
I dont care if the project is dead, this ticket stays open
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.
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.
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)
- 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
- 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
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!