Create a gist now

Instantly share code, notes, and snippets.

class SongsController < ApplicationController
# GET /songs
def index
@songs = Song.all
@uploader = Song.new.track
@uploader.success_action_redirect = new_song_url
end
# GET /songs/1
def show
@song = Song.find(params[:id])
end
# GET /songs/new
def new
@song = Song.new(key: params[:key])
end
# GET /songs/1/edit
def edit
@song = Song.find(params[:id])
end
# POST /songs
def create
@user = current_user
@song = @user.songs.build(params[:song])
if @song.save
flash[:success] = "Song created!"
redirect_to songs_path
else
render 'songs/new'
end
end
# PUT /songs/1
def update
@song = Song.find(params[:id])
if @song.update_attributes(params[:song])
flash[:success] = "Song updated!"
redirect_to songs_path
else
flash[:error] = "Unable to update song"
redirect_to songs_path
end
end
# DELETE /songs/1
def destroy
@song = Song.find(params[:id])
@song.destroy
if @song.destroy
flash[:success] = "Song deleted!"
redirect_to songs_path
else
flash[:error] = "Unable to delete song"
redirect_to songs_path
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment