JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources
Dealing with strong parameters with nested hash in JR
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 2.3k
- Forks
- 546
- PR merge metrics
- No merged PRs in 30d
Description
Not sure how to deal with this strong parameters issue in a JSONAPI::ResourceController.
I have a simple User model with settings field that is stored in Postgres as a jsonb field type. The resource looks like this:
class API::V1::UserResource < JSONAPI::Resource
key_type :uuid
attributes :username, :email, :first_name, :last_name, :roles
attribute :settings
def roles
@model.roles.to_a
end
end
This serializes out just fine, but trying to PATCH with something like the body below:
{
"data": {
"id": "776c526a-6b5f-4839-998e-591d3043645d",
"type": "users",
"attributes": {
"settings": {
"color": "blue"
}
}
}
}
If config.raise_if_parameters_not_allowed = false then I get this stored in the database:
"--- !ruby/object:ActionController::Parameters\nparameters: !ruby/hash:ActiveSupport::HashWithIndifferentAccess\n color: blue\npermitted: false\n"
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at JSONAPI::ResourceController's strong-parameter handling and reproduce the PATCH request for the User resource's jsonb settings field. The fix is complete when nested settings are stored as JSON data rather than a serialized ActionController::Parameters object.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- postgresql, rails, ruby
- Domain
- api, backend, database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100