NoMethodError (undefined method `permit' for "test":String):

1.6k Views Asked by At

I have a simple create action where I'm passing some params, but getting an error of undefined method permit for:

NoMethodError (undefined method `permit' for "twest":String):

following is the params that I'm getting in the request:

{"email"=>"[email protected]", "promo_code"=>"test", "description"=>"this is test", "action"=>"create"}

and the promo_code_params

def promo_code_params
  params.require(:promo_code).permit(:email,:code, :description)
end

the create action

def create
 @promo_code = @reward.promo_codes.new(promo_code_params)
 # code
 # code
end
1

There are 1 best solutions below

1
On

Your params hash is not on the expected way your promo_code_params defines. It should look like:

{ "promo_code" => {"email"=>"[email protected]", "code"=>"test", "description"=>"this is test"}, "action"=>"create"}

or you promo_code_params should be like:

def promo_code_params
  params.permit(:email,:promo_code,:description)
end

Hope that helps you understand what's wrong.