7

Builder を使用して優れた RSS フィードを作成する方法を示す多くの例が Web ( http://techoctave.com/c7/posts/32-create-an-rss-feed-in-railsなど) にあります。標準テンプレートは次のようなものです。

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では、すべてのコマンドが生成するようです...

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'
4

2 に答える 2

6

Rails 3.1.0.rc1もこのバグで壊れましたが、Ruby 1.8.7を使用している場合のみ-問題であることが判明しました.instruct!

一時的な解決策として、次のように xchar.rb にモンキー パッチを適用することができます (この投稿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
于 2011-06-24T14:53:03.437 に答える
3

Builder 3.0 と fast_xs 0.8.0 の両方がインストールされている場合にも、このエラーが発生します (hpricot には fast_xs 0.8.0 もバンドルされていることに注意してください)。

これは、次のモンキー パッチで回避できますapplication.rb

class String
  alias_method :orig_fast_xs, :fast_xs
  def fast_xs(ignore)
    orig_fast_xs
  end
end
于 2011-08-31T13:10:45.990 に答える