https://github.com/monade/underscorize_params
underscorize_params, a ruby Gem that allows you to send parameters in camelcase to your rails api, without worrying about to transform them in snakecase
https://github.com/monade/underscorize_params
gem parameters rails ruby
Last synced: about 1 month ago
JSON representation
underscorize_params, a ruby Gem that allows you to send parameters in camelcase to your rails api, without worrying about to transform them in snakecase
- Host: GitHub
- URL: https://github.com/monade/underscorize_params
- Owner: monade
- License: mit
- Created: 2022-05-31T12:41:57.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-04-18T07:32:05.000Z (about 2 years ago)
- Last Synced: 2024-04-21T01:51:58.280Z (about 2 years ago)
- Topics: gem, parameters, rails, ruby
- Language: Ruby
- Homepage: https://monade.io/en/home-en/
- Size: 20.5 KB
- Stars: 2
- Watchers: 6
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# underscorize_params
## Installation
Add the Gem into your Gemfile
```ruby
gem 'underscorize_params'
```
This gem allows you to send params to a Controller's action in camel case.
It gets included inside ActionController::Base
```ruby
ActionController::Base.include UnderscorizeParams::Controller if defined?(ActionController::Base)
```
Suppose you have these Controller and Model:
models/user.rb
```ruby
class User < ActiveRecord::Base
attribute :first_name, :String
attribute :last_name, :String
end
```
controllers/users_controller.rb
```ruby
class UsersController < ActionController::Base
def create
@user = User.new create_params
if @user.save
render json: @user
else
render json: @user.errors
end
end
private
def create_params
params.permit(:first_name, :last_name)
end
end
```
this gem allows you to call this controller's api with parameters in camel case, such as:
```typescript
const params = {
firstName: 'Friedrich',
lastName: 'Nietzsche'
}
axios.post('/users', params)
```
the gem's job is very simple, received parameters get transformed into snake case in the **before_action** hook.
Check out the code to find out, is very simple!
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
About Monade
----------------

underscorize_params is maintained by [mònade srl](https://monade.io).
We <3 open source software. [Contact us](https://monade.io/studio/contatti/) for your next project!