Skip to content

Instantly share code, notes, and snippets.

@leemcalilly
Created February 24, 2013 21:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leemcalilly/5025765 to your computer and use it in GitHub Desktop.
Save leemcalilly/5025765 to your computer and use it in GitHub Desktop.
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