Last active
December 24, 2017 12:23
-
-
Save vochicong/4e14a6764ed69c9c5c5d1f885dc85942 to your computer and use it in GitHub Desktop.
Rails APIでcamelCase ref: https://qiita.com/vochicong/items/d64f3b3d5a448a3b1f42
This file contains hidden or 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
# File: config/initializers/params_snakeizer.rb | |
# Transform JSON request param keys from JSON-conventional camelCase to | |
# Rails-conventional snake_case | |
module ActionController | |
# Modified from action_controller/metal/strong_parameters.rb | |
class Parameters | |
def deep_snakeize! | |
@parameters.deep_transform_keys!(&:underscore) | |
self | |
end | |
end | |
end |
This file contains hidden or 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
# File: config/initializers/params_snakeizer.rb | |
# Transform JSON request param keys from JSON-conventional camelCase to | |
# Rails-conventional snake_case | |
module ActionController | |
# Modified from action_controller/metal/strong_parameters.rb | |
class Parameters | |
def deep_snakeize! | |
@parameters.deep_transform_keys!(&:underscore) | |
self | |
end | |
end | |
end |
This file contains hidden or 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
# File: app/controllers/application_controller.rb | |
class ApplicationController < ActionController::API | |
protected | |
# Snakeize JSON API request params | |
def snakeize_params | |
params.deep_snakeize! | |
end | |
end |
This file contains hidden or 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
# File: app/controllers/application_controller.rb | |
class ApplicationController < ActionController::API | |
protected | |
# Snakeize JSON API request params | |
def snakeize_params | |
params.deep_snakeize! | |
end | |
end |
This file contains hidden or 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
class UsersController < ApplicationController | |
before_action :snakeize_params, only: [:say_hello, :say_goodbye] | |
# ..... | |
end |
This file contains hidden or 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
class UsersController < ApplicationController | |
before_action :snakeize_params, only: [:say_hello, :say_goodbye] | |
# ..... | |
end |
This file contains hidden or 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
# File: app/controllers/application_controller.rb | |
class ApplicationController < ActionController::API | |
before_action :snakeize_params | |
protected | |
# Snakeize JSON API request params | |
def snakeize_params | |
params.deep_snakeize! | |
end | |
end |
This file contains hidden or 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
# File: app/controllers/application_controller.rb | |
class ApplicationController < ActionController::API | |
before_action :snakeize_params | |
protected | |
# Snakeize JSON API request params | |
def snakeize_params | |
params.deep_snakeize! | |
end | |
end |
This file contains hidden or 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
json.key_format! camelize: :lower |
This file contains hidden or 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
json.key_format! camelize: :lower |
This file contains hidden or 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
Jbuilder.key_format camelize: :lower |
This file contains hidden or 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
Jbuilder.key_format camelize: :lower |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment