forked from saberma/shopqi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move validator class to standalone folder.
- Loading branch information
Showing
3 changed files
with
22 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# encoding: utf-8 | ||
class EmailFormatValidator < ActiveModel::EachValidator #用于邮件校验 | ||
|
||
def validate_each(object, attribute, value) | ||
unless value =~ /\A[^@]+@([^@\.]+\.)+[^@\.]+\z/ | ||
object.errors[attribute] << (options[:message] || "格式不对") | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# encoding: utf-8 | ||
class SkuValidator < ActiveModel::Validator #用于验证sku数量超过商店限制后不能再新增商品和款式 issues#282 | ||
|
||
def validate(record) | ||
shop = record.shop || record.product.try(:shop) | ||
if !shop.nil? && shop.plan_type.skus <= shop.variants.size | ||
record.errors[:base] << "超过商店限制" | ||
end | ||
end | ||
|
||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters