I have a User and a Shift. Users have many shifts.
class User < ActiveRecord::Base
has_many :shifts
end
class Shift < ActiveRecord::Base
belongs_to :user
end
One of my users can’t do one of their shifts and so wants to swap it with another user.
What is the best way to do this restfully? It seems that I need to update 2 shifts simultaneously: The shift that needs to be swapped and then then shift that it needs to be swapped with. Therefore, this doesn’t really fit with the edit and update actions which are intended for changing a single model.
This doesn’t fit neatly with any of the default RESTful routes for a single resource (member route). One possibility is to add a new RESTful collection route:
More at: http://guides.rubyonrails.org/routing.html#adding-more-restful-actions