Class: AttachmentMagick::ImagesController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/attachment_magick/images_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/attachment_magick/images_controller.rb', line 6

def create
  options = {
    :photo      => params[:Filedata],
    :source     => params[:source],
    :file_name  => (params[:Filedata].original_filename unless params[:source])
  }

  @image = @klass.images.create(options)
  @klass.save

  partial_options = {
    :collection => [@image],
    :as         => :image,
    :partial    => AttachmentMagick.configuration.default_add_partial
  }

  partial_options.merge!({:partial => params[:data_partial]}) if params[:data_partial].present?
  render partial_options
end

#destroyObject



35
36
37
38
39
# File 'app/controllers/attachment_magick/images_controller.rb', line 35

def destroy
  @klass.images.find(params[:id]).destroy

  render :text => "ok"
end

#update_sortableObject



26
27
28
29
30
31
32
33
# File 'app/controllers/attachment_magick/images_controller.rb', line 26

def update_sortable
  hsh = {}
  params[:images].each_with_index {|id, index| hsh.merge!({"#{index}" => {:id => "#{id}", :priority => index}}) }
  @klass.images_attributes = hsh
  @klass.save

  render :text => "ok"
end