I have a collaborative playlist and I want everybody that enters in my website could add a new track.
Search tracks and search for the playlist is already done but when I'm trying to add tracks to this playlist I get this error:
uninitialized class variable @@users_credentials in RSpotify::User
My code looks like this:
class SiteController < ApplicationController
before_action :authenticate, only: %i[search add_song]
def search
tracks = RSpotify::Track.search(params[:song])
render json: tracks
end
def add_song
@spotify_playlist = RSpotify::Playlist.find(
SPOTIFY_CONFIG['default']['username'],
SPOTIFY_CONFIG['default']['playlist_id']
)
song = params[:song]
@spotify_playlist.add_tracks!([song])
end
private
def authenticate
RSpotify.authenticate(SPOTIFY_CONFIG['default']['client_id'],
SPOTIFY_CONFIG['default']['client_secret'])
end
end
params[:song] is the track_uri.
Is there anything that I'm missing in order to get it working?
I have a collaborative playlist and I want everybody that enters in my website could add a new track.
Search tracks and search for the playlist is already done but when I'm trying to add tracks to this playlist I get this error: uninitialized class variable @@users_credentials in RSpotify::User
My code looks like this:
params[:song] is the track_uri.
Is there anything that I'm missing in order to get it working?