Controller Actions For acts_as_list Position Manipulation

One thing I took away from your courses was to try and stick to the seven standard actions and I’ve found this very helpful in focusing my thinking.

However I’m in the process of adding acts_as_list to a Photo model and I’m unsure of how to translate the process of updating a photo’s position in its owning Gallery. acts_as_list uses a position column on Photo to track the postion of the Photo within the gallery, allowing this position to be manipulated using methods like move_lower and move_higher and atomatically reordering photos accordingly.

Within My Gallery’s show view, I display a list of its photos, ordered by postion. For each photo I have an up and down arrow for moving that photo up or down in order.

In most examples I’ve seen that hook acts_as_list in to a Controller, there is an additional sort action on an existing controller. This doesn’t feel right to me.

The best solution I’ve come up with is to create a PhotoListController with a single update action that receives a PATCH containing the photo’s id and an offset. The action would use acts_as_list’s API to reorder the photos and redirect to the referrer. However, this doesn’t feel right either.

How would you suggest handling this situation?

I support trying to stick to the seven RESTful actions whenever possible. I think it’s totally fine to have a controller that does nothing but re-sort the list. I would rename it slightly to PhotoListSortOrdersController so that the name matches what you’re doing. You’re UPDATE-ing your sort order for photos.

Thanks for replying.

Just doesn’t feel quite right for some reason, but it has done the job.