save asset static file
This commit is contained in:
parent
a19e0dba6c
commit
0f7dce8aa6
|
@ -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
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue