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
d0a3119d
Commit
d0a3119d
authored
May 09, 2016
by
李福中
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add data type i18n
parent
88fb8ffc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
2 deletions
+16
-2
lib/rails_param/param.rb
+16
-2
No files found.
lib/rails_param/param.rb
View file @
d0a3119d
...
@@ -14,7 +14,7 @@ module RailsParam
...
@@ -14,7 +14,7 @@ module RailsParam
def
param!
(
name
,
type
,
options
=
{},
&
block
)
def
param!
(
name
,
type
,
options
=
{},
&
block
)
name
=
name
.
to_s
unless
name
.
is_a?
Integer
# keep index for validating elements
name
=
name
.
to_s
unless
name
.
is_a?
Integer
# keep index for validating elements
return
unless
params
.
member?
(
name
)
||
check_param_presence?
(
options
[
:default
])
||
options
[
:required
]
return
unless
params
.
member?
(
name
)
||
check_param_presence?
(
options
[
:default
])
||
options
[
:required
]
begin
begin
...
@@ -95,7 +95,7 @@ module RailsParam
...
@@ -95,7 +95,7 @@ module RailsParam
end
end
return
nil
return
nil
rescue
ArgumentError
rescue
ArgumentError
raise
InvalidParameterError
,
error_message_for
(
nil
,
"
#{
param
}
不是合法的:
#{
type
}
"
,
options
)
raise
InvalidParameterError
,
error_message_for
(
nil
,
"
#{
options
[
:label
]
||
param
}
不是合法的
#{
data_type_i18n
(
type
)
}
"
,
options
)
end
end
end
end
...
@@ -145,5 +145,19 @@ module RailsParam
...
@@ -145,5 +145,19 @@ module RailsParam
end
end
end
end
def
data_type_i18n
(
type
)
{
Integer
=>
'整数'
,
Float
=>
'数字'
,
String
=>
'字符串'
,
Date
=>
'日期'
,
Time
=>
'时间'
,
DateTime
=>
'日期时间'
,
Array
=>
'数组'
,
Hash
=>
'哈希'
,
BigDecimal
=>
'数字'
}
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