Skip to content

Instantly share code, notes, and snippets.

@leemcalilly
Created March 18, 2013 14: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/bcbccc9259c39d0b6b7a to your computer and use it in GitHub Desktop.
Save leemcalilly/bcbccc9259c39d0b6b7a to your computer and use it in GitHub Desktop.
class SongsController < ApplicationController
# GET /songs
def index
@songs = Song.all
if params[:tag]
@songs = Song.tagged_with(params[:tag])
else
@songs = Song.all
end
@alphabetical_songs = Song.all.group_by{|u| u.title[0]}
end
def upload
@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