I built a rails application were users can add music to their personal playlist. These playlists are only seen by the owner.
There is a "my" namespace with a playlists controller. Inside the controller I have a method to add a song to the playlist and remove.
def add
@post = Post.find params[:post_id]
@playlist = current_user.playlist
@playlist.posts << @post
redirect_to root_path, :flash => { :alert => "Added to playlist!"}
end
def remove
@playlist = current_user.playlist
@playlist.posts.delete(params[:post_id])
redirect_to my_playlist_path, :flash => { :alert => "Removed from playlist!"}
end
I understand how to pull all the music through the API since it is a GET request. But how would I keep the adding and removing of songs from the playlist in sync between the iOS app and web app.
"in sync" is a really complicated and involved subject. If you want true offline capabilities, and true "sync", you'll need to look into various options out there. But to simply use your rails backend as the data source for your iOS app is pretty easy. Just hit the endpoints to load or manipulate the data, and make the same changes to the iOS app UI.
Here are some phases, starting with the simplest:
Phase 1 (reloading the whole dataset every time)
Phase 2 (loading the dataset once, then handling each add/remove individually)
Phase 3 (loading the dataset once, handling each add/remove individually, with latency compensation)