Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 158
- Log:
Reconfigured all applications for use in the ROOL account with its
new layout. All files are set up for the development branch of the
filesystem. Caught up in this changeset is an unrelated modification
to the directory listing routine in Radiant, which now sorts the
entries alphabetically.
- Author:
- rool
- Date:
- Sun Dec 10 19:28:59 +0000 2006
- Size:
- 980 Bytes
1 | class Attachment < ActiveRecord::Base |
2 | belongs_to :post |
3 | |
4 | attr_writer :data |
5 | |
6 | include ErrorRaising |
7 | |
8 | def before_save |
9 | self.filename.gsub!(/[^a-z_\.\-0-9]/i, '_') |
10 | self.filename.gsub!(/^\.+/, '_') |
11 | end |
12 | |
13 | def after_save |
14 | # Create attachment directory |
15 | begin |
16 | Dir.mkdir(self.dir_path) |
17 | rescue Errno::EEXIST |
18 | end |
19 | # Save uploaded file to attachment directory |
20 | File.open(self.file_path, 'w') do |f| |
21 | f.write(@data) |
22 | end |
23 | @data = nil |
24 | end |
25 | |
26 | def after_destroy |
27 | # Delete file |
28 | File.delete self.file_path |
29 | # Delete directory |
30 | Dir.delete self.dir_path |
31 | end |
32 | |
33 | # Returns the directory of this attachment, e.g. /forum/public/attachments/12/ |
34 | def dir_path |
35 | RAILS_ROOT + RForum::CONFIG[:attachment_path] + "/#{self.id}/" |
36 | end |
37 | |
38 | def file_path |
39 | self.dir_path + self.filename |
40 | end |
41 | |
42 | def get_file_content |
43 | self.reload |
44 | File.read self.file_path |
45 | end |
46 | |
47 | def url |
48 | "/attachment/#{self.id}/#{self.filename}" |
49 | end |
50 | |
51 | end |