Sha256: e12bb0b3b0e03a20e5bb73671f2b9cb84f1857edaaf6a2b624d42b1a73a248d6

Contents?: true

Size: 1.44 KB

Versions: 15

Compression:

Stored size: 1.44 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])
          # 10.times {
            
            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}
          # render text: "successful"
        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

15 entries across 15 versions & 1 rubygems

Version Path
ruby_gallery-0.3.0.4 lib/ruby_gallery/attachments_controller.rb
ruby_gallery-0.3.0.3 lib/ruby_gallery/attachments_controller.rb
ruby_gallery-0.3.0.2 lib/ruby_gallery/attachments_controller.rb
ruby_gallery-0.3.0.1 lib/ruby_gallery/attachments_controller.rb
ruby_gallery-0.3.0 lib/ruby_gallery/attachments_controller.rb
ruby_gallery-0.2.9 lib/ruby_gallery/attachments_controller.rb
ruby_gallery-0.2.7 lib/ruby_gallery/attachments_controller.rb
ruby_gallery-0.2.6 lib/ruby_gallery/attachments_controller.rb
ruby_gallery-0.2.5 lib/ruby_gallery/attachments_controller.rb
ruby_gallery-0.2.4 lib/ruby_gallery/attachments_controller.rb
ruby_gallery-0.2.2 lib/ruby_gallery/attachments_controller.rb
ruby_gallery-0.2.1 lib/ruby_gallery/attachments_controller.rb
ruby_gallery-0.1.9 lib/ruby_gallery/attachments_controller.rb
ruby_gallery-0.1.8 lib/ruby_gallery/attachments_controller.rb
ruby_gallery-0.1.7 lib/ruby_gallery/attachments_controller.rb