Sha256: 7a0aff1e542d34af89246657a125df552cf62522fb4ff84d0b0b67fedf1d344b

Contents?: true

Size: 1.29 KB

Versions: 1

Compression:

Stored size: 1.29 KB

Contents

class AttachmentMagick::ImagesController < ActionController::Base
  # protect_from_forgery  :except => :create
  respond_to    :html, :js
  before_filter :load_klass

  def create
    @image = @klass.images.create(:photo => params[:Filedata], :source => params[:source], :image_type => params[:data_type])
    @klass.save

    if params[:data_partial].present?
      render :partial => params[:data_partial], :collection => [@image], :as => :image
    else
      render :partial => AttachmentMagick.configuration.default_add_partial, :collection => [@image], :as => :image, :locals => { :size => @klass.class.style_publisher }
    end
  end

  def update_sortable
    array_ids = params[:images]
    hash      = {}

    array_ids.each_with_index do |id, index|
      hash.merge!( {"#{index}" => {:id => "#{id}", :priority => index}} )
    end

    @klass.images_attributes = hash
    @klass.save

    render :text => "ok"
  end

  def destroy
    @klass.images.find(params[:id]).destroy
    render :text => "ok"
  end

  private

  def load_klass
    query   = ""
    objects = params[:data_attachment].split("_")
    objects = objects.in_groups_of(2)

    objects.each do |el|
      str = objects.index(el) == 0 ? "" : "."
      query << "#{str}#{el.first}.find('#{el.last}')"
    end

    @klass = eval(query)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
attachment_magick-0.1.0 app/controllers/attachment_magick/images_controller.rb