本文介绍了出现在 URL 中的 Rails 3 UTF-8 查询字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的主页上有一个搜索查询表单 (/)

I have a search query form on my home page (/)

<% form_tag(search_path, :method => :get) do %>
  <%= text_field_tag 'query' %>
  <%= submit_tag "Search", :name => nil%>

<% end %>

当我提交此搜索表单时,我希望以 (/search?query=foo) 结束.但是,现在我得到/search?utf8=%E2%9C%93&query=foo.那个 utf8 参数在那里做什么?我怎样才能摆脱它?

When I submit this search form, I want to end up at (/search?query=foo). However, right now I get /search?utf8=%E2%9C%93&query=foo. What's that utf8 parameter doing there? How can I get rid of it?

谢谢.

推荐答案

utf8 参数(以前称为 snowman) 是针对 Internet Explorer 错误的 Rails 3 解决方法.

The utf8 parameter (formerly known as snowman) is a Rails 3 workaround for an Internet Explorer bug.

简短的回答是 Internet Explorer 会忽略 POST 数据 UTF8 编码,除非 POST 数据中至少包含一个 UTF8 字符.为此,Rails 在表单中注入了一个 UTF8 字符,以强制 IE 将所有内容都视为 UTF8 编码.

The short answer is that Internet Explorer ignores POST data UTF8 encoding unless at least one UTF8 char is included in the POST data. For this reason, Rails injects an UTF8 character in the form to force IE to treat everything as UTF8 encoded.

这篇关于出现在 URL 中的 Rails 3 UTF-8 查询字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 12:35