Ruby on rails 3.2 如何修复UTF-8中的无效字节序列?
有时,当用户输入没有路由的链接时,我会显示一条很好的消息,如: *抱歉,此链接{@not\u found\u path}未从我们的旧网站迁移,或者您键入的链接不正确* 如何修复@not_found_path值,以避免出现错误: 模板中UTF-8中的字节序列无效?我已经安装了ruby 1.9.3和rails 3.2.11 有什么想法吗Ruby on rails 3.2 如何修复UTF-8中的无效字节序列?,ruby-on-rails-3.2,Ruby On Rails 3.2,有时,当用户输入没有路由的链接时,我会显示一条很好的消息,如: *抱歉,此链接{@not\u found\u path}未从我们的旧网站迁移,或者您键入的链接不正确* 如何修复@not_found_path值,以避免出现错误: 模板中UTF-8中的字节序列无效?我已经安装了ruby 1.9.3和rails 3.2.11 有什么想法吗 def render_404(exception) @not_found_path = exception.message respond_
def render_404(exception)
@not_found_path = exception.message
respond_to do |format|
format.html { render template: 'errors/not_found', layout: 'layouts/application', status: 404 }
format.all { render nothing: true, status: 404 }
end
end
我在视图中解决了它,如下所示:
The link #{content_tag(:span, @not_found_path.force_encoding("ISO-8859-1").encode("utf-8"), :class => 'text-error')} is not found, We are sorry for that, as we have migrated our website, we could not restore all the links.
我希望这将帮助一些人您需要通过配置文本编辑器将视图保存为有效的UTF8。