Controlador para la gestión de álbums en la WebTV
Auto complete para los tags
# File app/controllers/admin/albums_controller.rb, line 125 def auto_complete_for_album_tag_list_es auto_complete_for_tag_list(params[:album][:tag_list_es]) if @tags.length > 0 render :inline => "<%= content_tag(:ul, @tags.map {|t| content_tag(:li, t.nombre)}) %>" else render :nothing => true end end
Marca la foto elegida como portada para este álbum
# File app/controllers/admin/albums_controller.rb, line 104 def choose_cover @album = Album.find(params[:id]) aphoto = @album.album_photos.find_by_photo_id(params[:photo_id]) previous_cover = @album.album_photos.find_by_cover_photo(true) render :update do |page| if aphoto.update_attributes(:cover_photo => true) page.replace "photo_cover_#{aphoto.id}", :partial => "aphoto_cover", :locals => {:aphoto => aphoto} if previous_cover && previous_cover.update_attributes(:cover_photo => false) page.replace "photo_cover_#{previous_cover.id}", :partial => "aphoto_cover", :locals => {:aphoto => previous_cover} end end end end
Creación de un álbum
# File app/controllers/admin/albums_controller.rb, line 66 def create @album = Album.new(params[:album]) if @album.save flash[:notice] = "El album se ha creado correctamente" redirect_to admin_album_path(@album) else render :action => "new" end end
Eliminación de un álbum
# File app/controllers/admin/albums_controller.rb, line 92 def destroy @album = Album.find(params[:id]) if @album.destroy flash[:notice] = "El album ha sido eliminado" redirect_to admin_albums_path else flash[:error] = "El album no ha sido eliminado" redirect_to admin_album_path(@album) end end
Modificación de un álbum
# File app/controllers/admin/albums_controller.rb, line 77 def edit @album = Album.find(params[:id]) end
Listado de álbums
# File app/controllers/admin/albums_controller.rb, line 28 def index @sort_order = params[:sort] || "publish" case @sort_order when "publish" order = "featured DESC, created_at DESC, title_es" when "title" order = "featured DESC, lower(tildes(title_es)), created_at DESC" end conditions = [] if params[:q].present? conditions << "lower(tildes(coalesce(title_es, '') || ' ' || coalesce(title_eu, ''))) like '%#{params[:q].tildes.downcase}%'" end @albums = Album.paginate :page => params[:page], :conditions => conditions.join(' AND '), :order => order # @orphane_photos_counter = Photo.count(:conditions => "NOT EXISTS (SELECT 1 FROM album_photos WHERE album_photos.photo_id=photos.id)") # @first_orphane_photo = Photo.find(:first, # :conditions => "NOT EXISTS (SELECT 1 FROM album_photos WHERE album_photos.photo_id=photos.id)", # :order => "created_at DESC") end
Formulario de creación de álbum
# File app/controllers/admin/albums_controller.rb, line 61 def new @album = Album.new end
# File app/controllers/admin/albums_controller.rb, line 118 def publish @album = Album.find(params[:id]) @album.update_attributes(:draft => false) redirect_to :back end
Vista de un álbum
# File app/controllers/admin/albums_controller.rb, line 56 def show @album = Album.find(params[:id]) end
Actualización de un álbum
# File app/controllers/admin/albums_controller.rb, line 82 def update @album = Album.find(params[:id]) if @album.update_attributes(params[:album]) redirect_to admin_album_path(@album) else render :action => "new" end end