Rails 5: unable to retrieve hash values from parameter

前端 未结 4 1857
滥情空心
滥情空心 2020-12-05 04:32

I\'m running into a strange issue.

undefined method `values\' for #

is the error I get

4条回答
  •  感情败类
    2020-12-05 05:14

    Since Rails 5, params are of class 'ActionController::Parameters'

    If you do params.to_h you will get the following error.

    *** ActionController::UnfilteredParameters Exception: unable to convert 
    unpermitted parameters to hash
    

    You can do as follows to permit all the params and get as Hash format:

    parameters = params.permit(params.keys).to_h
    

    "But beware of using this! You are permitting all the params which may include unknown params that can harm your code."

提交回复
热议问题