Permalink
Browse files

fixed: duplicate customer addresses.

  • Loading branch information...
1 parent 89c4e4b commit ab22a89de2e17c13c73f0549094f17cb62cae47d @saberma saberma committed Jun 30, 2011
Showing with 3 additions and 9 deletions.
  1. +2 −8 app/models/order.rb
  2. +1 −1 config/initializers/client_side_validations.rb
View
10 app/models/order.rb
@@ -144,10 +144,7 @@ class OrderFulfillment < ActiveRecord::Base
class OrderBillingAddress < ActiveRecord::Base
belongs_to :order
validates_presence_of :name, :province, :city, :district, :address1, :phone, message: '此栏不能为空白'
-
- before_create do
- self.country = 'china'
- end
+ default_value_for :country, :china
def province_name
District.get(self.province)
@@ -166,10 +163,7 @@ def district_name
class OrderShippingAddress < ActiveRecord::Base
belongs_to :order
validates_presence_of :name, :province, :city, :district, :address1, :phone, message: '此栏不能为空白'
-
- before_create do
- self.country = 'china'
- end
+ default_value_for :country, :china
def province_name
District.get(self.province)
View
2 config/initializers/client_side_validations.rb
@@ -7,7 +7,7 @@
# Uncomment the following block if you want each input field to have the validation messages attached.
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
unless html_tag =~ /^<label/
- if instance.object_name =~ /^order/ # 无奈的特殊处理: 商店订单address页面的错误提示需要换行(必要时使用instance.method_name细化判断)
+ if instance.respond_to?(:object_name) and instance.object_name =~ /^order/ # 无奈的特殊处理: 商店订单address页面的错误提示需要换行(必要时使用instance.method_name细化判断)
%{<div class="field-with-errors"><span class="error-message">#{instance.error_message.first}</span><br/>#{html_tag}</div>}.html_safe
else
#将输入项的后面插入的field_with_errors div改为span,否则会破坏布局(比如[价格]输入项后面带'元','元'字会被移至下一行)

0 comments on commit ab22a89

Please sign in to comment.