0

I am using Rails 4 and the ActsAsList gem to give our Project model a position. Projects can be owned my one user, and collaborated on with many users. When a user re-orders their projects, it affects the project order for the collaborators as an unintended side-effect. Is there a way around this?

4
  • You can use the scope option on the acts_as_list gem and give it a symbol of the column name that you want it to scope to. github.com/swanandp/acts_as_list/blob/master/README.md#example It sounds like you have the position on the wrong table though. Without seeing your models it’s hard to tell for sure, but I would say that your project shouldn’t have a position column but instead the join table between projects and collaborators should. This will allow you to scope the acts_as_list on the collaborators_projects table to collaborator_id (given the join table idea).
    – Nate
    Commented Mar 5, 2019 at 1:16
  • Also for what it’s worth, I use the acts as list gem at work as well. We have photos on vehicles and the position is scoped to the vehicle id so that each vehicle has its own set of photo positions.
    – Nate
    Commented Mar 5, 2019 at 1:20
  • Hey @Nate thanks so much for your input. After reading the docs I wasn't quite sure how to use a scope but your explanation makes it very clear. I will give that a try, thanks! Commented Mar 5, 2019 at 14:10
  • No problem! Obviously if you end up having more questions about it, feel free to update this question with your new findings.
    – Nate
    Commented Mar 5, 2019 at 14:28

1 Answer 1

2

UPDATE Based on @nate's suggestion, I moved the :position column from the Project model to the Collaboration model which is the join table between Project and User. Then I included acts_as_list scope: :user_id on the Collaboration model and removed it from the Project model. Now each user has projects through collaborations and the position of each project is scoped to the user.

Not the answer you're looking for? Browse other questions tagged or ask your own question.