Class: AmpleAssets::FilesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/ample_assets/files_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/ample_assets/files_controller.rb', line 18

def create
  if uploadify?
    filename, filedata = params['Filename'], params['Filedata']
    file = File.new(:attachment => filedata)
  else
    file = File.new(params[:file])
  end
  if file.save
    if uploadify?
      render :nothing => true
    else
      redirect_to file_path(file)
    end
  else
    flash[:error] = "Whoops! There was a problem creating new asset."
    redirect_to :action => :index
  end
end

#destroyObject



45
46
47
48
49
50
51
52
53
# File 'app/controllers/ample_assets/files_controller.rb', line 45

def destroy
  current_file.destroy
  if request.xhr?
    render :nothing => true
  else
    flash[:notice] = 'Asset deleted successfully.'
    redirect_to request.referrer
  end
end

#gravityObject

Raises:

  • (ActiveRecord::RecordNotFound)


61
62
63
64
65
# File 'app/controllers/ample_assets/files_controller.rb', line 61

def gravity
  raise ActiveRecord::RecordNotFound if current_file.nil?
  current_file.update_attribute :attachment_gravity, params[:gravity]
  render :nothing => true
end

#newObject



14
15
16
# File 'app/controllers/ample_assets/files_controller.rb', line 14

def new
  render 'ample_assets/files/new', :layout => false, :content_type => :html if request.xhr?
end

#searchObject



67
68
69
70
71
72
73
74
# File 'app/controllers/ample_assets/files_controller.rb', line 67

def search
  @current_files = File.with_query("^#{params[:q]}")
  respond_to do |format|
    format.js { render current_files, :content_type => :html }
    format.json { render :json => current_files.to_json }
    format.html { render :nothing => true }
  end
end

#showObject

Raises:

  • (ActiveRecord::RecordNotFound)


37
38
39
40
41
42
43
# File 'app/controllers/ample_assets/files_controller.rb', line 37

def show
  raise ActiveRecord::RecordNotFound if current_file.nil?
  respond_to do |format|
    format.json { render :json => current_file.to_json }
    format.html
  end
end

#touchObject

Raises:

  • (ActiveRecord::RecordNotFound)


55
56
57
58
59
# File 'app/controllers/ample_assets/files_controller.rb', line 55

def touch
  raise ActiveRecord::RecordNotFound if current_file.nil?
  current_file.touch
  render :nothing => true
end