This repository has been archived by the owner on Jan 25, 2022. It is now read-only.
-
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.
refs #17 新規投稿: 画像のサイズチェックをJS側で行うように変更
- Loading branch information
YOSHIDA Hiroki
committed
Nov 7, 2013
1 parent
063ae6b
commit 5471635
Showing
4 changed files
with
27 additions
and
24 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
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
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
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,14 @@ | ||
class ImageAspectValidator < ActiveModel::Validator | ||
def validate(record) | ||
width = record.send(options[:width]) | ||
height = record.send(options[:height]) | ||
record.errors.add(:base, "Aspect ratio that not meet #{options[:aspect].join(':')}.") unless avable_aspect?(width, height) | ||
end | ||
|
||
def avable_aspect?(width, height) | ||
horizontal_aspect = options[:aspect][0] | ||
vertical_aspect = options[:aspect][1] | ||
aspect = width / height * 1.0 | ||
aspect < (horizontal_aspect / vertical_aspect * 1.0) && aspect > (vertical_aspect / horizontal_aspect * 1.0) | ||
end | ||
end |