Class: ActsAsAssets::AssetsController

Inherits:
ApplicationController
  • Object
show all
Includes:
AssetsHelper
Defined in:
app/controllers/acts_as_assets/assets_controller.rb

Instance Method Summary collapse

Methods included from AssetsHelper

#asset_action, #asset_file_name, #asset_file_path, #asset_id, #asset_label, #asset_target, #assets_body, #destroy_file_path, #destroy_link, #destroy_method_for, #destroy_path, #get_file_path, #get_method_for, #get_path, #name_from, #upload_complete_js_function

Instance Method Details

#createObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/acts_as_assets/assets_controller.rb', line 17

def create
  @model = assets_base_model
  @asset = klazz.create(:asset => params[:file],
                        :asset_content_type => mime_type(params[:file]),
                        klazz.base_model_sym => @model)
  @download_prefix = klazz.download_prefix
  @asset_partial = partial_to_use(@asset)
  respond_to do |format|
    if @asset.valid?
      load_assets
      format.js
    else
      format.js { render :json => {:success => false, :errors => @asset.errors} }
    end
  end
end

#destroyObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/acts_as_assets/assets_controller.rb', line 34

def destroy
  begin
    @model = assets_base_model
    @download_prefix = klazz.download_prefix
    @asset = klazz.find_by_id(params[:asset_id])
    @asset_partial = partial_to_use(@asset)
    @asset.destroy
  rescue Exception => e
    error = e.message
  end

  respond_to do |format|
    if error.nil?
      format.js
    else
      format.js { render :json => {:success => false, :errors => error} }
    end
  end

end

#getObject



55
56
57
58
59
60
61
62
# File 'app/controllers/acts_as_assets/assets_controller.rb', line 55

def get
  begin
    @asset = klazz.find(params[:asset_id])
    send_file(file_to_download_path, {:filename => File.basename(@asset.asset.path), :content_type => @asset.asset_content_type, :disposition => 'inline'})
  rescue ActiveRecord::RecordNotFound
    respond_with_404
  end
end

#indexObject



9
10
11
12
13
14
15
# File 'app/controllers/acts_as_assets/assets_controller.rb', line 9

def index
  @model = assets_base_model
  respond_to do |format|
    format.html { render :layout => false }
    format.json { render :json => @assets }
  end
end