Class: Tenon::AssetsController

Inherits:
ResourcesController show all
Defined in:
app/controllers/tenon/assets_controller.rb

Instance Method Summary collapse

Methods inherited from ResourcesController

#destroy, #initialize, #new, #reorder

Constructor Details

This class inherits a constructor from Tenon::ResourcesController

Instance Method Details

#createObject



20
21
22
23
24
25
# File 'app/controllers/tenon/assets_controller.rb', line 20

def create
  asset = Tenon::Asset.new(resource_params)
  flash[:notice] = 'Asset was successfully uploaded.' if asset.save && !request.xhr?
  @asset = asset.decorate
  respond_with(@asset, location: assets_path)
end

#cropObject



43
44
45
# File 'app/controllers/tenon/assets_controller.rb', line 43

def crop
  render layout: false
end

#editObject



16
17
18
# File 'app/controllers/tenon/assets_controller.rb', line 16

def edit
  render layout: false
end

#indexObject



3
4
5
6
7
8
9
10
11
12
13
14
# File 'app/controllers/tenon/assets_controller.rb', line 3

def index
  respond_to do |format|
    format.html
    format.json do
      @assets = Tenon::Asset.all
      @assets = @assets.where(search_args) if params[:q]
      @assets = @assets.with_type(params[:type]) unless params[:type].blank?
      @assets = @assets.paginate(per_page: 20, page: params[:page])
      @assets = Tenon::PaginatingDecorator.decorate(@assets)
    end
  end
end

#updateObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/tenon/assets_controller.rb', line 27

def update
  if resource_params[:duplicate] == '1'
    new_asset = Tenon::Asset.new(resource_params)
    new_asset.attachment = @asset.attachment
    new_asset.save
    new_asset.crop_x = nil
    working_asset = new_asset
  else
    working_asset = @asset
    working_asset.update_attributes(resource_params)
  end
  working_asset.attachment.reprocess! if working_asset.cropping?
  @asset = working_asset.decorate
  respond_with(@asset, location: polymorphic_index_path)
end