Class: UsefullAttachment::LinksController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/usefull_attachment/links_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/usefull_attachment/links_controller.rb', line 13

def create
  ##UserSession.log("Admin::AttachmentController#create params=#{params[:admin_attachment].inspect}")
  user = current_user ? {:created_by => current_user.id, :updated_by => current_user.id} : {}
  Attachment.create(params[:usefull_attachment_attachment].deep_merge!(user)) if params[:usefull_attachment_attachment].present?
  Avatar.create(params[:usefull_attachment_avatar].deep_merge!(user)) if params[:usefull_attachment_avatar].present?
  Link.create(params[:usefull_attachment_link].deep_merge!(user)) if params[:usefull_attachment_link].present?
  redirect_to :action => "index", :notice => t("created")
rescue => e
  flash[:alert] = t("not_created", :message => e.message)
  redirect_to :back
end

#destroyObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/usefull_attachment/links_controller.rb', line 38

def destroy
  @attachment = Link.find(params[:id])
  @attachment.destroy

  respond_to do |format|
    format.html do
      redirect_to :back, :notice => t("deleted")
    end
    format.xml  { head :ok }
  end
  
rescue => e
  flash[:alert] = t("not_deleted", :message => e.message)
  redirect_to :back
end

#downloadObject



25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/usefull_attachment/links_controller.rb', line 25

def download
  @attachment = Link.find(params[:id])
  respond_to do |format|
    format.html do
      raise FileMissing.new(:file => @attachment.link.path) unless File.exist?(@attachment.link.path)
      send_file @attachment.link.path, :type => @attachment.link_content_type
    end
  end
rescue => e
  flash[:alert] = t("not_downloaded", :message => e.message)
  redirect_to :back
end

#indexObject



3
4
5
6
# File 'app/controllers/usefull_attachment/links_controller.rb', line 3

def index
  @search = Link.search(params[:search])
  @attachments = @search.paginate(:page => params[:page])
end

#newObject



8
9
10
11
# File 'app/controllers/usefull_attachment/links_controller.rb', line 8

def new
  @attachment = Link.new
  #UserSession.log("Admin::AttachmentController#new params=#{params[:admin_attachment].inspect}, @attachment=#{@attachment.inspect}")
end