Ruby on Rails 3表单中的_snowman参数是什么? [英] What is the _snowman param in Ruby on Rails 3 forms for?

查看:149
本文介绍了Ruby on Rails 3表单中的_snowman参数是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Ruby on Rails 3中(目前使用Beta 4),我发现当使用 form_tag form_for 时,助手有一个名为 _snowman 的隐藏字段,其值为☃( Unicode \x9731)显示出来。



那么,这是干什么用的? >解决方案

这里是为了支持Internet Explorer 5并鼓励它使用 UTF-8 的形式。



提交消息见 here 详细说明如下:


修复几个已知的网页编码问题: p>


  • 在所有表单上指定accept-charset。所有最近的浏览器以及
    IE5 +都将使用指定
    的编码作为表单参数

  • 不幸的是,IE5 +不会查看accept-charset,除非至少有一个
    字符在表单的值中不是
    在页面的字符集中。由于
    用户可以覆盖默认的
    charset(Rails设置为UTF-8),
    ,我们提供一个隐藏的输入,其中包含
    a unicode字符,强制IE为
    查看accept-charset。
  • 现在绝大多数web输入都是UTF-8,我们将入站
    参数设置为UTF-8。这将
    消除了ASCII-8BIT和

    UTF-8之间不兼容的
    编码的许多情况。

  • 您可以安全地忽略params [ _snowman]


总之,您可以放心地忽略此参数。 b

不过,我不确定为什么我们会支持Internet Explorer 5这样的旧技术。如果你问我,这看起来像是一个非Ruby on Rails的决定。


In Ruby on Rails 3 (currently using Beta 4), I see that when using the form_tag or form_for helpers there is a hidden field named _snowman with the value of ☃ (Unicode \x9731) showing up.

So, what is this for?

解决方案

This is here to support Internet Explorer 5 and encourage it to use UTF-8 for its forms.

The commit message seen here details it as follows:

Fix several known web encoding issues:

  • Specify accept-charset on all forms. All recent browsers, as well as IE5+, will use the encoding specified for form parameters
  • Unfortunately, IE5+ will not look at accept-charset unless at least one character in the form's values is not in the page's charset. Since the user can override the default
    charset (which Rails sets to UTF-8), we provide a hidden input containing a unicode character, forcing IE to look at the accept-charset.
  • Now that the vast majority of web input is UTF-8, we set the inbound parameters to UTF-8. This will eliminate many cases of incompatible encodings between ASCII-8BIT and
    UTF-8.
  • You can safely ignore params[:_snowman]

In short, you can safely ignore this parameter.

Still, I am not sure why we're supporting old technologies like Internet Explorer 5. It seems like a very non-Ruby on Rails decision if you ask me.

这篇关于Ruby on Rails 3表单中的_snowman参数是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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