Expecting params hash but getting a string (Rails)

ぃ、小莉子 提交于 2019-12-08 07:06:59

问题


I have a typical signup form which has, for example, three fields: login, password, and email. We're using rails' form helpers, so we are expecting these to come to us in a hash named user.

Something close to what we'd expect:

Parameters: {"action"=>"new", "controller"=>"users", "user"=>{"password"=>"[FILTERED]", "login"=>"new_user_login", "email"=>"new_user_email"}}

We then do stuff like: params[:user].merge(SOME_HASH) # some other stuff we want to save into the user object

A few times a day we're getting "undefined method `merge' for String", and looking at those requests, the params are instead coming in as:

Parameters: {"action"=>"new", "controller"=>"users", "user"=>"login=new_user_login&email=new_user_email&password=[FILTERED]"}

params[:user], which we expect to be a hash, is coming in as a single query string, leading to the error.

Has anyone else seen this in their logs? It's coming from the same form as the others, and it's a valid POST with authenticity_token set, etc. And looking for that login in our DB, we found that the user retried the request and succeeded.

Could it also be at the fault of the browser? This individual was Firefox 3.6 on a Mac.

来源:https://stackoverflow.com/questions/5835987/expecting-params-hash-but-getting-a-string-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!