Skip to content

Instantly share code, notes, and snippets.

@artyomlagun
Created December 16, 2020 13:23
Show Gist options
  • Save artyomlagun/62babe36fca7932baf1d76231d1fcfdc to your computer and use it in GitHub Desktop.
Save artyomlagun/62babe36fca7932baf1d76231d1fcfdc to your computer and use it in GitHub Desktop.
Convert params key from JS practics to Ruby
#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