Skip to content

Instantly share code, notes, and snippets.

@leemcalilly
Created March 18, 2013 15:02
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/da673a9240b0517de274 to your computer and use it in GitHub Desktop.
Save leemcalilly/da673a9240b0517de274 to your computer and use it in GitHub Desktop.
class AlbumsController < ApplicationController
before_filter :require_login
# GET /albums
def index
@albums = Album.all
end
# GET /albums/1
def show
@album = Album.find(params[:id])
end
# GET /albums/new
def new
@album = Album.new
@album.songs.build
end
# GET /albums/1/edit
def edit
@album = Album.find(params[:id])
end
# POST /albums
def create
@user = current_user
@album = @user.albums.build(params[:album])
if @album.save
flash[:success] = "Album created!"
redirect_to albums_path
else
render 'albums/new'
end
end
# PUT /albums/1
def update
@album = Album.find(params[:id])
if @album.update_attributes(params[:album])
flash[:success] = "Album updated!"
redirect_to albums_path
else
flash[:error] = "Unable to update album"
redirect_to albums_path
end
end
# DELETE /albums/1
def destroy
@album = Album.find(params[:id])
@album.destroy
if @album.destroy
flash[:success] = "Album deleted!"
redirect_to albums_path
else
flash[:error] = "Unable to delete album"
redirect_to albums_path
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment