public
Created

  • Download Gist
gistfile1.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.