Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActionController::UnfilteredParameters (unable to convert unpermitted parameters to hash) - Rails 5

i have this error but not quite sure how to solve it. I have an API version module VI and my usercontroller module is like this

class Api::V1::UsersController < ApplicationController
  def register
    ap params
  end

  def user_params
    params.require(:user).permit(
      :email, :password,:password_confirmation, :username, :name, :fb_id, :picture, :access_token, :reset_password_token,
      :sign_in_count, :authenticatable_salt, :current_sign_in_at, :last_sign_in_at, :current_sign_in_ip, :last_sign_in_ip
    )
  end
end

I have a register function and each time i want to log the params, i get an error

ActionController::UnfilteredParameters (unable to convert unpermitted parameters to hash)

Not sure how to solve this given that i have already permitted the attributes for my user model already.

I didnt include the gem strong_parameters but not sure if i have to because i dont think i have to include it.

I know permitting the attributes would have worked for Rails 4 not sure why it is not working for Rails 5. Do i need to do anything on my model as well?

like image 213
Kingsley Simon Avatar asked Sep 03 '25 02:09

Kingsley Simon


1 Answers

You created the method user_params, but in the register action you are using params (that is, unfiltered parameters).

So change this:

def register
  ap params
end

to this:

def register
  ap user_params
end
like image 109
Gerry Avatar answered Sep 05 '25 05:09

Gerry