save asset static file

This commit is contained in:
Wen-Tien Chang 2010-02-05 16:15:16 +08:00
parent a19e0dba6c
commit 0f7dce8aa6
3 changed files with 14 additions and 1 deletions

View File

@ -9,6 +9,11 @@ class Asset
has_grid_attachment :data, :required => true
before_validation :setup_filename
after_save :save_static_file
def url
"/assets/#{self.filename}"
end
protected
@ -18,4 +23,10 @@ class Asset
end
end
def save_static_file
f = File.new("#{RAILS_ROOT}/public/assets/#{self.filename}", "wb")
f.write(self.data.file.read)
f.close
end
end

View File

@ -13,7 +13,9 @@
<% @assets.each do |asset| %>
<tr>
<td><%= link_to asset.filename, admin_asset_path(asset) %></td>
<td><%#= link_to asset.filename, admin_asset_path(asset) %>
<%= link_to asset.url, asset.url %>
</td>
<td><%= asset.description %></td>
<td><%= asset.data.content_type %></td>
<td><%= asset.data.file_name %></td>

0
public/assets/.gitignore vendored Normal file
View File