-
-
Save leemcalilly/da673a9240b0517de274 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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