Rails 5: unable to retrieve hash values from parameter

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

I\'m running into a strange issue.

undefined method `values\' for #

is the error I get

4条回答
  •  Happy的楠姐
    2020-12-05 05:09

    I think what's happening is the following:

    In a console you are working with a simple hash called attributes. As a hash the attributes parameter in the console has a valid instance method called values.

    In your rails app the params hash is not a simple hash any more. It is an instance of the ActionController::Parameters class. As an instance of that class it does not have an instance method called values, but it does have an instance method called to_h & to_unsafe_h, which would accomplish your goals. After calling to_h on your parameters you can call the values method.

提交回复
热议问题