需要参数哈希但得到一个字符串 (Rails)
我有一个典型的注册表单,其中包含三个字段:登录名、密码和电子邮件。我们正在使用 Rails 的表单助手,因此我们期望它们以名为 user 的哈希形式提供给我们。
接近我们期望的东西:
参数:{"action"=>"new", "controller"=>"users", "user"=>{"password"=>"[ FILTERED]", "login"=>"new_user_login", "email"=>"new_user_email"}}
然后我们会执行以下操作: params[:user].merge(SOME_HASH) # 我们想要保存到用户对象中的其他一些东西
每天我们都会收到“字符串的未定义方法‘merge’”,并且查看这些请求,参数是相反,输入为:
参数:{"action"=>"new", "controller"=>"users", "user"=>"login=new_user_login&email=new_user_email&password=[FILTERED]"}
params[:user],我们期望是一个散列,以单个查询字符串的形式出现,到错误。
有其他人在他们的日志中看到过这一点吗?它与其他表单来自相同的表单,并且是设置了authenticity_token 等的有效POST。在我们的数据库中查找该登录,我们发现用户重试了请求并成功。
难道也是浏览器的错?此人是 Mac 上的 Firefox 3.6。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论