instance method
key_format!
Ruby on Rails 2.7.0
Since v2.4.1 Last seen in v2.14.1Signature
key_format!(*args)
Specifies formatting to be applied to the key. Passing in a name of a function will cause that function to be called on the key. So :upcase will upper case the key. You can also pass in lambdas for more complex transformations.
Example:
json.key_format! :upcase json.author do json.name "David" json.age 32 end { "AUTHOR": { "NAME": "David", "AGE": 32 } }
You can pass parameters to the method using a hash pair.
json.key_format! camelize: :lower json.first_name "David" { "firstName": "David" }
Lambdas can also be used.
json.key_format! ->(key){ "_" + key } json.first_name "David" { "_first_name": "David" }
Parameters
-
argsrest
Source
# File lib/jbuilder.rb, line 100
def key_format!(*args)
@key_formatter = KeyFormatter.new(*args)
end
Defined in lib/jbuilder.rb line 100
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in Jbuilder