From 0f7dce8aa637de6f3c03f8af0ef62af5d2f4f7c3 Mon Sep 17 00:00:00 2001 From: Wen-Tien Chang Date: Fri, 5 Feb 2010 16:15:16 +0800 Subject: [PATCH] save asset static file --- app/models/asset.rb | 11 +++++++++++ app/views/admin/assets/index.html.erb | 4 +++- public/assets/.gitignore | 0 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 public/assets/.gitignore diff --git a/app/models/asset.rb b/app/models/asset.rb index 05ae63e7..09d6dbd4 100644 --- a/app/models/asset.rb +++ b/app/models/asset.rb @@ -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 \ No newline at end of file diff --git a/app/views/admin/assets/index.html.erb b/app/views/admin/assets/index.html.erb index abf9d16a..be6a23ea 100644 --- a/app/views/admin/assets/index.html.erb +++ b/app/views/admin/assets/index.html.erb @@ -13,7 +13,9 @@ <% @assets.each do |asset| %> - <%= link_to asset.filename, admin_asset_path(asset) %> + <%#= link_to asset.filename, admin_asset_path(asset) %> + <%= link_to asset.url, asset.url %> + <%= asset.description %> <%= asset.data.content_type %> <%= asset.data.file_name %> diff --git a/public/assets/.gitignore b/public/assets/.gitignore new file mode 100644 index 00000000..e69de29b