Sha256: 2ee86a43f3e94bdc00668f6c04a78ecebf3bfe00b6ac9af3b2829d11c6d2d2bb

Contents?: true

Size: 1.27 KB

Versions: 2

Compression:

Stored size: 1.27 KB

Contents

class Admin::PhotosController < Admin::BaseController
  respond_to :html, :js  
  layout false
  
  def create
    photographable_id = params[:photographable_id]
    photographable_class = params[:photographable_type].constantize
    @photographable = photographable_class.find(photographable_id)
    
      if @photographable.respond_to?(:photos) # <- has_many :photos
        @photo = @photographable.photos.build({:image => params[:file]})
      else # <- has_one :photo
        @photo = @photographable.build_photo({:image => params[:file]})
      end
      
      if @photo.save
        respond_with(@photo)
      else
        render :status => 500
      end

  end

  def search
    @photos = Photo.tagged_with(params[:q]).page(params[:page])
    respond_with(@photos)
  end
  
  def edit
  end
  
  def rotate
     @photo ||= Photo.find(params[:id])
     rotation = params[:deg].to_f
     rotation ||= 90
     @photo.rotate!(rotation)
#     flash[:notice] = "The image has been rotated"
   end
  
  
  def update
      @photo.attributes = params[:photo]
      @photo.save
      if request.format == "json"      
        render :json => {:success => true} 
      else
        respond_with(@photo)
      end
  end
  
  def destroy
      @photo.destroy
      respond_with(@photo)
  end
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fullstack-cms-0.3.10 app/controllers/admin/photos_controller.rb
fullstack-cms-0.3.9 app/controllers/admin/photos_controller.rb