My favorites | Sign in
Project Home Downloads Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions

Issue 58 attachment: files_controller.rb (1.4 KB)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#
#
#
class Admin::FilesController < Admin::BaseController

# Lists all assets / file uploads in the system.
def index
@title = "List of user uploaded files"

if params[:sort] == 'name' then
sort = "filename ASC"
else
sort = "created_on DESC"
end

# Set currently viewing by key
if params[:key] then
@viewing_by = params[:key]
@title << " - #{@viewing_by.pluralize}"
@files = UserUpload.paginate(
:order => sort,
:page => params[:page],
:conditions => ["type = ? and thumbnail is NULL", @viewing_by],
:per_page => 30
)
else
@files = UserUpload.paginate(
:order => sort,
:page => params[:page],
:conditions => "thumbnail is NULL",
:per_page => 30
)
end

end

# Removes a file via AJAX
#
def destroy
@file = UserUpload.find(params[:id])
if @file
@file.destroy
end
# Render nothing to denote success
render_text "" and return
end

# Uploads files.
#
def upload
files_saved = 0
# Build product images from upload
params[:file].each do |i|
if i[:file_data] && !i[:file_data].blank?
new_file = UserUpload.init(i[:file_data])
if new_file.save
files_saved += 1
end
end
end
flash[:notice] = "#{files_saved} file(s) uploaded."
redirect_to :action => 'index' and return
end

end
Powered by Google Project Hosting