Sha256: 79d8cd7d8452f6e6952ad9a82c0dede77039d6ad7026917a8ff7c18f43b01979

Contents?: true

Size: 1.55 KB

Versions: 2

Compression:

Stored size: 1.55 KB

Contents

class IshManager::PhotosController < IshManager::ApplicationController

  # @TODO: this is bad? _vp_ 20170513
  skip_authorization_check :only => [ :j_create ]
  protect_from_forgery :except => [ :j_create] 

  def without_gallery
    @photos = Photo.unscoped.where( :gallery => nil, :is_trash => false )
  end

  def destroy
    @photo = Photo.unscoped.find params[:id]
    authorize! :destroy, @photo
    @photo.is_trash = true
    @photo.save
    redirect_to request.referrer
  end

  def show
    @photo = Photo.unscoped.find params[:id]
  end

  def j_create
    @photo = Photo.new params[:photo].permit!
    authorize! :create, @photo
    @photo.is_public = true
   
    if params[:galleryname]
      gallery = Gallery.unscoped.where( :galleryname => params[:galleryname] ).first
      @photo.gallery_id = gallery.id
    elsif params[:gallery_id]
      gallery = Gallery.unscoped.where( :galleryname => params[:gallery_id] ).first
      gallery ||= Gallery.find( params[:gallery_id] )
      @photo.gallery_id = gallery.id
    end

    # cache
    @photo.gallery.site.touch if @photo.gallery.site
    @photo.gallery.city.touch if @photo.gallery.city

    if @photo.save
      j = { :name => @photo.photo.original_filename,
        :size => @photo.photo.size,
        :url => @photo.photo.url( :large ),
        :thumbnail_url => @photo.photo.url( :thumb ),
        :delete_url => photo_path(@photo),
        :delete_type => 'DELETE',
        :name => @photo.name
      }
      render :json => [ j ]
    else
      render :json => { "errors" => @photo.errors } 
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ish_manager-0.1.8.5 app/controllers/ish_manager/photos_controller.rb
ish_manager-0.1.8.4 app/controllers/ish_manager/photos_controller.rb