photomix/app/controllers/collections_controller.rb

87 lines
3.7 KiB
Ruby
Raw Normal View History

2009-06-03 01:33:39 +02:00
class CollectionsController < ApplicationController
2009-08-03 16:39:33 +02:00
before_filter :check_public_access
2012-07-24 23:26:16 +02:00
skip_before_filter :authenticate_user!, :only => [:index, :show]
2012-07-29 00:33:03 +02:00
add_breadcrumb I18n.t('home_page'), :root_path, :title => I18n.t('home_page')
2009-06-03 01:33:39 +02:00
def index
2012-07-29 00:33:03 +02:00
add_breadcrumb t('activerecord.models.collection.popular'), collections_path, :title => t('activerecord.models.collection.popular')
add_breadcrumb t('activerecord.actions.create', :model => I18n.t('activerecord.models.collection.single')), new_collection_path,
:title => t('activerecord.actions.create'), :li_icon => 'icon-plus-sign'
@collections = Collection.popular.page(@page).per(@per_page)
2012-07-26 22:26:23 +02:00
2009-06-03 01:33:39 +02:00
respond_to do |format|
format.html
format.json { render :json => @collections }
format.xml { render :xml => @collections }
end
end
def show
2009-06-16 01:18:42 +02:00
@collection = Collection.find( params[:id] )
2012-07-29 00:33:03 +02:00
add_breadcrumb t('activerecord.models.collection.popular'), collections_path, :title => t('activerecord.models.collection.popular')
add_breadcrumb @collection.title, collection_path(@collection), :title => @collection.title
add_breadcrumb t('activerecord.actions.update', :model => I18n.t('activerecord.models.collection.single')), edit_collection_path,
:title => t('activerecord.actions.update', :model => I18n.t('activerecord.models.collection.single'))
add_breadcrumb t('activerecord.actions.destroy', :model => I18n.t('activerecord.models.collection.single')),collection_path(@collection),
:title => t('activerecord.actions.destroy', :model => I18n.t('activerecord.models.collection.single'))
@albums = @collection.albums.includes(:photos).where("photos.id NOT NULL").order('albums.rating_average desc').page(@page).per(@per_page)
2009-06-03 01:33:39 +02:00
respond_to do |format|
format.html
format.json { render :json => @collection }
format.xml { render :xml => @collection }
format.pdf { render :pdf => @collection.title }
end
end
def new
@collection = Collection.new
2012-07-30 21:08:48 +02:00
add_breadcrumb t('activerecord.models.collection.other').mb_chars.capitalize.to_s, collections_path,
:title => t('activerecord.models.collection.other')
add_breadcrumb t('activerecord.actions.new', :model => I18n.t('activerecord.models.collection.one')), new_collection_path,
:title => t('activerecord.actions.new', :model => I18n.t('activerecord.models.collection.one'))
2009-06-03 01:33:39 +02:00
end
def create
@collection = Collection.new(params[:collection])
if @collection.save
2010-10-11 16:03:34 +02:00
flash[:notice] = "Collection created! Now lets add a new album."
redirect_to new_collection_album_path(@collection)
2009-06-03 01:33:39 +02:00
else
render :action => :new
end
end
def edit
2009-06-16 01:22:51 +02:00
@collection = Collection.find( params[:id])
2009-06-03 01:33:39 +02:00
end
def update
2009-06-16 01:22:51 +02:00
@collection = Collection.find( params[:id])
2012-07-29 00:33:03 +02:00
add_breadcrumb t('activerecord.models.collection.popular'), collections_path, :title => t('activerecord.models.collection.popular')
add_breadcrumb t('activerecord.actions.create', :model => I18n.t('activerecord.models.collection.single')), new_collection_path, :title => t('activerecord.actions.create')
2009-06-03 01:33:39 +02:00
if @collection.update_attributes(params[:collection])
2009-06-09 00:30:22 +02:00
flash[:notice] = "Collection updated!"
2009-06-03 01:33:39 +02:00
redirect_to @collection
else
render :action => :edit
end
end
def destroy
2009-06-16 01:22:51 +02:00
@collection = Collection.find( params[:id])
2009-06-03 01:33:39 +02:00
if @collection.destroy
redirect_to collections_path
else
redirect_to @collection
end
end
2012-07-26 22:26:23 +02:00
def rate
@collection = Collection.find(params[:id])
@collection.rate(params[:stars], current_user, params[:dimension])
render :json => {:id => @collection.wrapper_dom_id(params), :width => 125}
end
2009-06-03 01:33:39 +02:00
end