This repository has been archived on 2020-05-27. You can view files and clone it, but cannot push or open issues/pull-requests.
tuxbliki/app/controllers/albums.rb

69 lines
1.5 KiB
Ruby
Raw Normal View History

2008-06-27 00:13:15 -04:00
class Albums < Application
def index
2008-06-27 21:28:18 -04:00
acount = Album.count
@page = params[:page].to_i
per_page = 12
@page_count = (acount.to_f / per_page.to_f).ceil.to_i
@page = 0 if @page >= @page_count
@url_key = :albums
@albums = Album.find(:all, :limit => per_page, :offset => (@page * per_page), :order => 'name ASC')
2008-06-27 00:13:15 -04:00
@tags = Album.popular_tags(30)
display @albums
end
def show
@album = Album.find_by_name(params[:id].gsub(/_/, ' '))
raise NotFound unless @album
display @album
end
def new
only_provides :html
@secondary_title = 'Create an album'
@album = Album.new(params[:album])
render
end
def create
@album = Album.new(params[:album])
if @album.save
redirect url(:album, @album.name.gsub(/ /, '_'))
else
@secondary_title = 'Create an album'
render :new
end
end
def edit
only_provides :html
@album = Album.find_by_name(params[:id].gsub(/_/, ' '))
@secondary_title = 'Update an album'
raise NotFound unless @album
render
end
def update
@album = Album.find_by_name(params[:id].gsub(/_/, ' '))
raise NotFound unless @album
@secondary_title = 'Update an album'
if @album.update_attributes(params[:album])
redirect url(:album, @album.name.gsub(/ /, '_'))
else
raise BadRequest
end
end
def delete
@album = Album.find_by_name(params[:id].gsub(/_/, ' '))
raise NotFound unless @album
if @album.destroy
redirect url(:albums)
else
raise BadRequest
end
end
end