vigetlabs / olive_branch

Handle camel/snake/dash case conversion
MIT License
180 stars 29 forks source link

ActionController::UnpermittedParameters: found unpermitted parameters: #47

Open kevincraig opened 3 years ago

kevincraig commented 3 years ago

I am getting the error ActionController::UnpermittedParameters: found unpermitted parameters: when doing a post to our API.

Currently, I have Application.rb setup as follows: config.middleware.use OliveBranch::Middleware, inflection: 'camel', content_type_check: -> (content_type) { true }

All of my GET requests work fine, so far every POST is failing with the error except my login endpoint, I'm digging through that to see if I can find a difference that would cause this issue.

This is from the logs on the request so I can see that it is converting it to snake case. I have this happening on multiple controllers.
:params => { "appointment" => { "address_id" => "22", "start_at" => "2021-06-18T17:30:00", "origin" => "paw", "appointment_vehicles_attributes" => [ { "package_id" => "18", "upgrade_ids" => [ "2", "3" ], "vehicle_id" => "1" } ] } },

dce commented 3 years ago

Hey @kevincraig what do you have set up for your permitted parameters for that request?

kevincraig commented 3 years ago

@dce Here is the params list, currently just require it to be 'appointment' hopefully I didn't misspell something. ha..

json_params.require(:appointment).permit(:id, :aasm_state, :upcharge_reason, :tax_amount, :tax_rate, :tax_description, :travel_fee, :travel_fee_description, :start_at, :origin,
:address_id, :promo_code, :promo_code_value, :promo_code_description, :promo_code_text, :via_partner_code, :promo_amount, :package_ids => [], :upgrade_ids => [], appointment_vehicles_attributes: [:id, :review_rating, :review_comments, :package_id,
:vehicle_id, :interior_condition, :interior_condition_notes,
:exterior_condition, :exterior_condition_notes, :upgrade_ids => []])
dce commented 3 years ago

Hmm, look OK to me. Does it give any more info after "found unpermitted parameters" (like what the params are)?

kevincraig commented 3 years ago

found unpermitted parameters: addressId, startAt, appointmentVehiclesAttributes Some additional information, this instance of the API is running on Docker and we are currently on Rails 4.2(I know). We're moving to 5.2 soon.

dce commented 3 years ago

Hey @kevincraig nothing's jumping out at me -- possible that json_params method is doing something funny?

kevincraig commented 3 years ago

@dce No problem. I'll poke around some more on my end. I'm also going to pull down our 5.2 Branch and give it a try as well. I'll update the issue either way.

kevincraig commented 3 years ago

Just a quick update, I migrated my branch to Rails 5.0 and I still see the same error, I have one other POST endpoint that is working but it has params.require(:class).permit!. I changed that on the other controller and I am now getting other errors but that's not idea to have to use permit!.

kevincraig commented 3 years ago

@dce well I figured out what the issue is, just not exactly sure how to go about fixing it. It looks like anytime I have an endpoint with params that are 2 words or more the post fails. For example, when creating a vehicle object I have year, make, model, subModel, vehicleTypeId. When I try and post that I get the error. Now if I take that exact call and change subModel => sub_model and vehicleTypeId => vehicle_type_id everything works fine. I know the gem is working from a GET aspect as all my requests come back in camel case. I'm at a loss right now but will keep digging.