https://github.com/tanmen/wrap_attributes
https://github.com/tanmen/wrap_attributes
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/tanmen/wrap_attributes
- Owner: tanmen
- License: mit
- Created: 2019-12-15T22:35:16.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-03-08T20:26:36.000Z (almost 3 years ago)
- Last Synced: 2025-08-19T14:35:10.327Z (4 months ago)
- Language: Ruby
- Size: 62.5 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: MIT-LICENSE
Awesome Lists containing this project
README
# WrapAttributes

add '_attributes' suffix in rails
## Usage
```ruby
class ApplicationController < ActionController::API
include WrapAttributes::AttributesWrapper # <- add
end
```
```ruby
# request parameter
# { 'username' => 'tanmen', 'posts' => [{'text' => 'hallo'}] }
# ↓
# wrapped parameter
# { 'username' => 'tanmen', 'posts_attributes' => [{'text' => 'hallo'}] }
class UsersController < ApplicationController
wrap_attributes :posts # <- add
private
def user_params
params.require(:user).permit(:username, :posts_attributes)
end
end
```
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'wrap_attributes'
```
And then execute:
```bash
$ bundle
```
Or install it yourself as:
```bash
$ gem install wrap_attributes
```
## Contributing
Contribution directions go here.
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).