Rails 3.1 Edge 是否打破了 XmlMarkup::Builder? [英] Is Rails 3.1 Edge breaking XmlMarkup::Builder?

查看:32
本文介绍了Rails 3.1 Edge 是否打破了 XmlMarkup::Builder?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

网上有很多例子(比如http://techoctave.com/c7/posts/32-create-an-rss-feed-in-rails) 展示了如何使用 Builder 制作漂亮的 RSS 提要.规范模板是这样的:

There are a number of examples on the Web (such as http://techoctave.com/c7/posts/32-create-an-rss-feed-in-rails) showing how to make a nice RSS feed using Builder. The canonical template is something like this:

xml.instruct! :xml, :version => "1.0" 
xml.rss :version => "2.0" do
xml.channel do
  xml.title "Your Blog Title"
  xml.description "A blog about software and chocolate"
  xml.link posts_url

  for post in @posts
    xml.item do
      xml.title post.title
      xml.description post.content
      xml.pubDate post.posted_at.to_s(:rfc822)
      xml.link post_url(post)
      xml.guid post_url(post)
    end
  end
end

这在 Rails 3.0.7 中运行良好.在 Rails 3.1 Edge 中,每个命令似乎都会产生...

This works fine in Rails 3.0.7. In Rails 3.1 Edge, every command seems to produce...

Rendered home/index.rss.builder (25.2ms)
Completed 500 Internal Server Error in 875ms

ActionView::Template::Error (wrong number of arguments (1 for 0)):
1: xml.instruct!(:xml, :encoding => "UTF-8")
2: 
3: xml.rss :version => "2.0" do
4:   xml.channel do
app/views/home/index.rss.builder:1:in   `_app_views_home_index_rss_builder___2123990471_2215695900'
app/controllers/home_controller.rb:17:in `index'
app/controllers/home_controller.rb:11:in `index'

推荐答案

Rails 3.1.0.rc1 对我来说也有这个错误,但只有在使用 Ruby 1.8.7 时 - 结果是 有问题.指示!

Rails 3.1.0.rc1 broke for me with this bug too, but only when using Ruby 1.8.7 - turns out it's a problem with .instruct!

作为临时解决方案,您可以使用以下内容对 xchar.rb 进行猴子补丁(如本文作者的建议 http://lists.alioth.debian.org/pipermail/pkg-ruby-extras-maintainers/2010-June/005411.html):

As a temporary solution you could monkeypatch xchar.rb with the following (as suggested by the author of this post http://lists.alioth.debian.org/pipermail/pkg-ruby-extras-maintainers/2010-June/005411.html):

--- /home/prahal/xmlbase.rb.orig  2010-06-03 11:18:38.000000000 +0200
+++ /home/prahal/xmlbase.rb.new 2010-06-03 11:18:53.000000000 +0200
@@ -131,7 +131,11 @@
       end
     else
       def _escape(text)
-        text.to_xs((@encoding != 'utf-8' or $KCODE != 'UTF8'))
+        begin
+   text.to_xs((@encoding != 'utf-8' or $KCODE != 'UTF8'))
+        rescue
+   text.to_xs()
+        end
       end
     end

这篇关于Rails 3.1 Edge 是否打破了 XmlMarkup::Builder?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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