deleting tar for products on update

This commit is contained in:
Alexey Nayden 2011-04-14 14:28:24 +04:00
parent 87845c3ac9
commit 055dfe665d
2 changed files with 24 additions and 2 deletions

View File

@ -16,10 +16,26 @@ class Product < ActiveRecord::Base
scope :recent, order("name ASC") 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 protected
def destroy_tar?
self.tar.clear if @delete_tar == "1"
end
def merge_tar_errors def merge_tar_errors
errors[:tar] += errors[:tar_content_type] errors[:tar] += errors[:tar_content_type]
errors[:tar_content_type] = [] errors[:tar_content_type] = []
end end
end end

View File

@ -14,8 +14,14 @@
= f.label :menu, t("activerecord.attributes.product.menu"), :class => :label = f.label :menu, t("activerecord.attributes.product.menu"), :class => :label
= f.text_area :menu, :class => 'text_field', :cols => 80 = f.text_area :menu, :class => 'text_field', :cols => 80
.group .group
= f.label :tar, t("activerecord.attributes.product.tar"), :class => :label %p
= f.file_field :tar, :class => 'file_field' = 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 .group.navform.wat-cf
%button.button{:type => "submit"} %button.button{:type => "submit"}