I have a question about the <Related Products> plu...
# support
j
I have a question about the Related Products plugin.
Spree::Relation
records have a position field that is nil by default; they have to be reordered before the position number gets assigned (it doesn't appear to use
acts_as_list
-- the assignment occurs in
Spree::Admin::RelationsController
). Is there a better way of changing this behavior than overriding the controller/view?
c
Looking at the change that added this here and it seems like you are right, this is set only on the controller action that is probably associated with the drag-n-drop in the admin. You could probably add a decorator to the model to make this behave as
acts_as_list
based on the instructions here https://github.com/brendon/acts_as_list#adding-acts_as_list-to-an-existing-model. You are probably going to want to scope the ordering as well, though I am not exactly sure how this gem works so I wouldn’t know on which field (maybe by
relation_type
and
relateable_id
). Alternatively you can also override the model and add a custom hook that does something similar to what
acts_as_list
would do on a
before_save
hook.
j
Thanks, Chris. It sounds like the simplest approach is to add
acts_as_list
to the model, which shouldn't clash with the existing functionality.
c
Yeah, I would think so! If you give that a try and it ends up working out for you, it might be a neat change to send upstream as well. Seems a bit strange that it wasn't done initially.