Closed tbcooney closed 3 years ago
Hi @tbcooney, this sounds familiar. Another user had the same problem: https://github.com/swanandp/acts_as_list/issues/303
However their fix was not that helpful to you. The main issue here is that your model class is being initialised before acts_as_list
has been injected into ActiveRecord::Base. Something in your setup must be triggering this. Often it's because one is referencing the class name (as a class name, not a string) somewhere in the Rails initialisation logic. If that facility allows you to pass a string instead of a class (e.g. 'Image'
not Image
then do that instead.
I hope that gives you something to go on. Please post your results back here so that it can help others :)
Thanks for the response @brendon ! Real head scratcher for me.
In terms of set up, I'm not doing anything "fancy" per say that would trigger this or touch the Rails initialization logic. I'm following the same set up steps for both dummy applications - steps that worked in 'rails', '~> 5.2.0'
with gem 'acts_as_list', '~> 0.9.17'
and failing in Rails 6.0
on 'acts_as_list', '~> 0.9.17'
and 'acts_as_list', '~> 0.9.19'
.
Could you elaborate on passing a string instead of a class to the facility? I'm not exactly sure what that means :/
Thanks @tbcooney. It's a strange one.
Some libraries such as sorcery
ask for a model to use for the 'user' in the system (as an example). This is defined in an initialiser file, and if defined as a class constant, will initialise the class at that point. They give you the option to pass the class as a string so that it can be constantised later on.
It'd be ideal if the stack trace could trace where the class is being initialised.
In the past I've been stung by using straight class constants inside other constants on a model. It can create circular reference problems etc...
Sorry I can't be more specific in your instance. Are you able to reproduce this on a bare-bones rails install?
Right on - yeah this is pretty bare-bones; I've only created two models through a has_many
association. One of the models has an position
attribute that is an integer
. I start to run into the error manipulating that position
in console. Specifically, I have a list of photos where I'm trying to make one image become the cover photo of that list (designated through position 1).
I've got the same issue with Rails 6.1.3. Any luck finding a solution to that?
Hi @andreyuhai, this one can be tricky. Are you doing anything to initialise your class too early in the boot up process? Simply referring to the class in an initialiser can cause it.
Hi @andreyuhai, this one can be tricky. Are you doing anything to initialise your class too early in the boot up process? Simply referring to the class in an initialiser can cause it.
Sorry for the late reply, I figured that it was my fault. I had not restarted the server.
Yep, that'd probably do it :D
I'm using Rails
6.0
withgem 'acts_as_list', '~> 0.9.19'
(I've also tried lower versions), and can not seem to getacts_as_list
working. Below is an example trying to grab the last image, to later perform a positional change.Models