Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
rails_param
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
ikcrm_common
rails_param
Commits
88fb8ffc
Commit
88fb8ffc
authored
Jan 04, 2016
by
李福中
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace error message from english to chinese
parent
be52d8da
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
11 deletions
+19
-11
lib/rails_param/param.rb
+19
-11
No files found.
lib/rails_param/param.rb
View file @
88fb8ffc
...
...
@@ -95,7 +95,7 @@ module RailsParam
end
return
nil
rescue
ArgumentError
raise
InvalidParameterError
,
"'
#{
param
}
' is not a valid
#{
type
}
"
raise
InvalidParameterError
,
error_message_for
(
nil
,
"
#{
param
}
不是合法的:
#{
type
}
"
,
options
)
end
end
...
...
@@ -103,9 +103,9 @@ module RailsParam
options
.
each
do
|
key
,
value
|
case
key
when
:required
raise
InvalidParameterError
,
"Parameter is required"
if
value
&&
param
.
nil?
raise
InvalidParameterError
,
error_message_for
(
value
,
"不能为空"
,
options
)
if
value
&&
param
.
nil?
when
:blank
raise
InvalidParameterError
,
"Parameter cannot be blank"
if
!
value
&&
case
param
raise
InvalidParameterError
,
error_message_for
(
value
,
"不能为空"
,
options
)
if
!
value
&&
case
param
when
String
!
(
/\S/
===
param
)
when
Array
,
Hash
...
...
@@ -114,28 +114,36 @@ module RailsParam
param
.
nil?
end
when
:format
raise
InvalidParameterError
,
"Parameter must be a string if using the format validation"
unless
param
.
kind_of?
(
String
)
raise
InvalidParameterError
,
"Parameter must match format
#{
value
}
"
unless
param
=~
value
raise
InvalidParameterError
,
error_message_for
(
value
,
"格式不正确"
,
options
)
unless
param
.
kind_of?
(
String
)
raise
InvalidParameterError
,
error_message_for
(
value
,
"必须匹配格式:
#{
value
}
"
,
options
)
unless
param
=~
value
when
:is
raise
InvalidParameterError
,
"Parameter must be
#{
value
}
"
unless
param
===
value
raise
InvalidParameterError
,
error_message_for
(
value
,
"必须等于:
#{
value
}
"
,
options
)
unless
param
===
value
when
:in
,
:within
,
:range
raise
InvalidParameterError
,
"Parameter must be within
#{
value
}
"
unless
param
.
nil?
||
case
value
raise
InvalidParameterError
,
error_message_for
(
value
,
"必须包含于:
#{
value
}
"
,
options
)
unless
param
.
nil?
||
case
value
when
Range
value
.
include?
(
param
)
else
Array
(
value
).
include?
(
param
)
end
when
:min
raise
InvalidParameterError
,
"Parameter cannot be less than
#{
value
}
"
unless
param
.
nil?
||
value
<=
param
raise
InvalidParameterError
,
error_message_for
(
value
,
"不能小于:
#{
value
}
"
,
options
)
unless
param
.
nil?
||
value
<=
param
when
:max
raise
InvalidParameterError
,
"Parameter cannot be greater than
#{
value
}
"
unless
param
.
nil?
||
value
>=
param
raise
InvalidParameterError
,
error_message_for
(
value
,
"不能大于:
#{
value
}
"
,
options
)
unless
param
.
nil?
||
value
>=
param
when
:min_length
raise
InvalidParameterError
,
"Parameter cannot have length less than
#{
value
}
"
unless
param
.
nil?
||
value
<=
param
.
length
raise
InvalidParameterError
,
error_message_for
(
value
,
"长度不能小于:
#{
value
}
"
,
options
)
unless
param
.
nil?
||
value
<=
param
.
length
when
:max_length
raise
InvalidParameterError
,
"Parameter cannot have length greater than
#{
value
}
"
unless
param
.
nil?
||
value
>=
param
.
length
raise
InvalidParameterError
,
error_message_for
(
value
,
"长度不能大于:
#{
value
}
"
,
options
)
unless
param
.
nil?
||
value
>=
param
.
length
end
end
end
def
error_message_for
(
value
,
message
,
options
)
if
options
[
:message
].
present?
return
options
[
:message
]
else
"
#{
options
[
:label
]
}#{
message
}
"
%
value
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment