Sha256: a1c4b688892d1137dc268241b37060d084947f17e611be19583b76ac2de2f706
Contents?: true
Size: 1.55 KB
Versions: 1
Compression:
Stored size: 1.55 KB
Contents
class Admin::PhotoAlbumsController < Admin::ApplicationController before_action :album, only: [:show, :edit, :update, :destroy, :library] add_breadcrumb 'Photo Albums', :admin_photo_albums_path layout 'admin/spud_photos' belongs_to_spud_app :photo_albums def index @photo_albums = SpudPhotoAlbum.all respond_with @photo_albums end def show respond_with @photo_album end def new @photo_album = SpudPhotoAlbum.new respond_with @photo_album end def create @photo_album = SpudPhotoAlbum.new(photo_album_params) write_photo_order if @photo_album.save respond_with @photo_album, location: admin_photo_albums_path end def edit respond_with @photo_album end def update @photo_album.update_attributes(photo_album_params) if @photo_album.save write_photo_order flash[:notice] = 'Album updated successfully' end respond_with @photo_album, location: admin_photo_albums_path end def destroy flash.now[:notice] = 'Album deleted successfully' if @photo_album.destroy respond_with @photo_album, location: admin_photo_albums_path end def album @photo_album = SpudPhotoAlbum.find(params[:id]) end private def write_photo_order order_ids = params[:spud_photo_album][:photo_ids] || [] @photo_album.spud_photo_albums_photos.each do |obj| index = order_ids.index(obj.spud_photo_id.to_s) obj.update_attribute(:sort_order, index) end end def photo_album_params params.require(:spud_photo_album).permit(:title, :url_name, photo_ids: []) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
tb_photos-1.2.0 | app/controllers/admin/photo_albums_controller.rb |