51 lines
1.1 KiB
Ruby
51 lines
1.1 KiB
Ruby
class AlbumsController < ApplicationController
|
|
before_filter :authenticate_user!
|
|
|
|
def index
|
|
@albums = Album.mine_or_friends(params[:friends], current_user).paginate :page => params[:page], :order => 'created_at DESC'
|
|
end
|
|
|
|
def create
|
|
@album = current_user.post(:album, params[:album])
|
|
|
|
if @album.created_at
|
|
flash[:notice] = "Successfully created album."
|
|
redirect_to @album
|
|
else
|
|
flash[:error] = "Successfully failed."
|
|
redirect_to albums_path
|
|
end
|
|
end
|
|
|
|
def new
|
|
@album = Album.new
|
|
end
|
|
|
|
def destroy
|
|
@album = Album.first(:id => params[:id])
|
|
@album.destroy
|
|
flash[:notice] = "Successfully destroyed album."
|
|
redirect_to albums_url
|
|
end
|
|
|
|
def show
|
|
@photo = Photo.new
|
|
@album = Album.first(:id => params[:id])
|
|
@album_photos = @album.photos
|
|
end
|
|
|
|
def edit
|
|
@album = Album.first(:id => params[:id])
|
|
end
|
|
|
|
def update
|
|
@album = Album.first(:id => params[:id])
|
|
if @album.update_attributes(params[:album])
|
|
flash[:notice] = "Successfully updated album."
|
|
redirect_to @album
|
|
else
|
|
render :action => 'edit'
|
|
end
|
|
end
|
|
|
|
end
|