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
Hide 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
...
@@ -95,7 +95,7 @@ module RailsParam
end
end
return
nil
return
nil
rescue
ArgumentError
rescue
ArgumentError
raise
InvalidParameterError
,
"'
#{
param
}
' is not a valid
#{
type
}
"
raise
InvalidParameterError
,
error_message_for
(
nil
,
"
#{
param
}
不是合法的:
#{
type
}
"
,
options
)
end
end
end
end
...
@@ -103,9 +103,9 @@ module RailsParam
...
@@ -103,9 +103,9 @@ module RailsParam
options
.
each
do
|
key
,
value
|
options
.
each
do
|
key
,
value
|
case
key
case
key
when
:required
when
:required
raise
InvalidParameterError
,
"Parameter is required"
if
value
&&
param
.
nil?
raise
InvalidParameterError
,
error_message_for
(
value
,
"不能为空"
,
options
)
if
value
&&
param
.
nil?
when
:blank
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
when
String
!
(
/\S/
===
param
)
!
(
/\S/
===
param
)
when
Array
,
Hash
when
Array
,
Hash
...
@@ -114,28 +114,36 @@ module RailsParam
...
@@ -114,28 +114,36 @@ module RailsParam
param
.
nil?
param
.
nil?
end
end
when
:format
when
:format
raise
InvalidParameterError
,
"Parameter must be a string if using the format validation"
unless
param
.
kind_of?
(
String
)
raise
InvalidParameterError
,
error_message_for
(
value
,
"格式不正确"
,
options
)
unless
param
.
kind_of?
(
String
)
raise
InvalidParameterError
,
"Parameter must match format
#{
value
}
"
unless
param
=~
value
raise
InvalidParameterError
,
error_message_for
(
value
,
"必须匹配格式:
#{
value
}
"
,
options
)
unless
param
=~
value
when
:is
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
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
when
Range
value
.
include?
(
param
)
value
.
include?
(
param
)
else
else
Array
(
value
).
include?
(
param
)
Array
(
value
).
include?
(
param
)
end
end
when
:min
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
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
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
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
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
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