Sha256: dd3fd20ad8d9eb5acb547d2c304808cb4497a949feb6e5e0855aea85ea747ab9

Contents?: true

Size: 1.34 KB

Versions: 1

Compression:

Stored size: 1.34 KB

Contents

module RubyGallery
  module AttachmentsController
    def upload_album_for(models)
      class_name = models.to_s.singularize
      class_object_name = class_name.classify # "Book"
      class_object = class_object_name.constantize # Book
      
      
      instance_eval do
        define_method("upload_album") do
          object = class_object.find(params[:id])
          photo = object.album_photos.build({photo: (params[:file] and params[:file].is_a?(Array)) ? params[:file][0] : params[:file]})
          photo.save 
          eval("@#{class_name} = #{class_object_name}.find(params[:id])")
          render :partial => "shared/photo_box",locals: {photo: photo}
        end
        
        define_method("delete_photo") do
          object = class_object.find(params[:id])
          photo = object.album_photos.find(params[:photo_id])
          photo.destroy
          render text: "ok"
        end
        
        define_method("update_ruby_gallery_position") do
          
          object = class_object.find(params[:id])
          json = params[:json]
      	  json.each do |key,value|
      	    id = value['id']
      	    position = value['position'] 
      	    photo = object.album_photos.find(id)
      	    photo.update_attribute(:position, position)
      	  end
          render :text => "successful"
        end
        
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ruby_gallery-0.3.0.6 lib/ruby_gallery/attachments_controller.rb