Rails:post参数中的引号丢失 [英] Rails: losing quotes in post parameters

查看:162
本文介绍了Rails:post参数中的引号丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将全文搜索添加到我的Rails站点,并允许用户在搜索输入框中输入双引号.问题是双引号似乎被Mongrel过滤掉了,所以我从没在params哈希值中收到这些引号.如何防止这种情况发生?我正在运行Rails 2.3.8.

I'm adding full-text search to my Rails site and allowing users to enter double quotes in the search input box. The problem is that the double quotes seem to get filtered out by Mongrel and so I never receive those quotes in the values of the params hash. How do I prevent this from happening? I'm running Rails 2.3.8.

在Firebug中,我看到post参数正确地用引号引起来了:

In Firebug I see the post parameter being posted correctly with quotes:

search_criteria "great post"

但是,在开发日志中,引号已消失:

In the development log, however, the quotes are gone:

处理PostsController#search(用于 127.0.0.1,2010年6月18日17:28:45)[POST]参数: {"search_criteria" =>优秀文章", "action" =>搜索","authenticity_token" =>"xUaOc1IAyjQmKn1NGqBpPVaTBmD4ayPq/lUJsqJGCxY =", "controller" =>帖子"}

Processing PostsController#search (for 127.0.0.1 at 2010-06-18 17:28:45) [POST] Parameters: {"search_criteria"=>"great post", "action"=>"search", "authenticity_token"=>"xUaOc1IAyjQmKn1NGqBpPVaTBmD4ayPq/lUJsqJGCxY=", "controller"=>"posts"}

当我在控制器中记录params [:search_criteria]的内容和大小时,我得到:

And when I log the contents and size of params[:search_criteria] in the controller, I get:

search criteria = great post
search criteria size = 10

当引用的字符串在另一个字符(例如,英文字符)后面或后面时,不会发生上述问题.一个空间.

This problem described above does not occur when the quoted string is trailed or preceded by another character, e.g. a space.

推荐答案

显然,这是机架1.1.0中的错误.已针对机架1.2.0进行了修复[在此处修补].但是,从2.3.6到2.3.10的actionpack(以及由此而来的rails)取决于机架〜> 1.1.0,因此它们都存在此问题.

Apparently this is a bug in rack 1.1.0. The fix [patch here] was made for rack 1.2.0. However, actionpack (and thus, rails) 2.3.6 through 2.3.10 depend on rack ~> 1.1.0, so they all have this problem.

最有可能实际发生的潜在解决方案排在第一位...

Potential solutions with most likely actually happening ordered first...

  • 根据上述修补程序修补机架的副本
  • 升级到Rails 3

此问题包含有关如何修补机架的提示

This question has tips on how to patch rack.

这篇关于Rails:post参数中的引号丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆