Created
December 16, 2020 13:23
-
-
Save artyomlagun/62babe36fca7932baf1d76231d1fcfdc to your computer and use it in GitHub Desktop.
Convert params key from JS practics to Ruby
This file contains 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
#config/application.rb | |
class SnakeCaseParametersMiddleware | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
request = ActionDispatch::Request.new(env) | |
request.request_parameters.deep_transform_keys!(&:underscore) | |
request.query_parameters.deep_transform_keys!(&:underscore) | |
@app.call(env) | |
end | |
end | |
module MyApp | |
class Application < Rails::Application | |
config.middleware.use(SnakeCaseParametersMiddleware) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment