From 055dfe665d0d772ea920eea10824ad266eee9a38 Mon Sep 17 00:00:00 2001 From: Alexey Nayden Date: Thu, 14 Apr 2011 14:28:24 +0400 Subject: [PATCH] deleting tar for products on update --- app/models/product.rb | 16 ++++++++++++++++ app/views/products/_form.html.haml | 10 ++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/app/models/product.rb b/app/models/product.rb index e59bde390..a9c890def 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -16,10 +16,26 @@ class Product < ActiveRecord::Base scope :recent, order("name ASC") + before_save :destroy_tar? + + def delete_tar + @delete_tar ||= "0" + end + + def delete_tar=(value) + @delete_tar = value + end + protected + def destroy_tar? + self.tar.clear if @delete_tar == "1" + end + def merge_tar_errors errors[:tar] += errors[:tar_content_type] errors[:tar_content_type] = [] end + + end diff --git a/app/views/products/_form.html.haml b/app/views/products/_form.html.haml index 2df5f1467..52450b5b6 100644 --- a/app/views/products/_form.html.haml +++ b/app/views/products/_form.html.haml @@ -14,8 +14,14 @@ = f.label :menu, t("activerecord.attributes.product.menu"), :class => :label = f.text_area :menu, :class => 'text_field', :cols => 80 .group - = f.label :tar, t("activerecord.attributes.product.tar"), :class => :label - = f.file_field :tar, :class => 'file_field' + %p + = f.label :tar, t("activerecord.attributes.product.tar"), :class => :label + = f.file_field :tar, :class => 'file_field' + %p + - if @product.tar? + = link_to @product.tar_file_name, @product.tar.url + = f.check_box :delete_tar + = f.label :delete_tar, t('layout.delete') .group.navform.wat-cf %button.button{:type => "submit"}