Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails 3.1.1中的to_xml方法抛出(参数数目错误(1代表0))异常_Ruby On Rails_Ruby_Xml_Ruby On Rails 3.1_Builder - Fatal编程技术网

Ruby on rails Rails 3.1.1中的to_xml方法抛出(参数数目错误(1代表0))异常

Ruby on rails Rails 3.1.1中的to_xml方法抛出(参数数目错误(1代表0))异常,ruby-on-rails,ruby,xml,ruby-on-rails-3.1,builder,Ruby On Rails,Ruby,Xml,Ruby On Rails 3.1,Builder,这真的很烦人。我的rails应用程序中的to_xml方法抛出了(参数数目错误(1代表0))异常。下面是我的代码 string={:job_id=>'123'} string.to_xml :skip_instruct => true, :root => 'line-item' 我深入研究了ActiveRecord::Base并找到了to_xml方法 def to_xml(options = {}) require 'builder' options[:indent]

这真的很烦人
。我的rails应用程序中的to_xml
方法抛出了
(参数数目错误(1代表0))
异常。下面是我的代码

string={:job_id=>'123'}
string.to_xml :skip_instruct => true, :root => 'line-item'
我深入研究了
ActiveRecord::Base
并找到了
to_xml
方法

 def to_xml(options = {})
  require 'builder'
  options[:indent] ||= 2
  xml = options[:builder] ||= ::Builder::XmlMarkup.new(:indent => options[:indent])
  xml.instruct! unless options[:skip_instruct]
  xml.level_one do
   xml.tag!(:second_level, 'content')
  end
 end

这里可能有什么问题?谢谢。

在您的代码和库中搜索定义#to_xml而没有参数的人。我试图在我创建的模块中编写
to_xml
方法,将
字符串
从上面扩展到该模块,并通过模块调用相同的方法,但错误相同。这是错误的
to_xml
,您想要的。但不管怎样,对xml的调用是可以的。你是说你在某处把自己的
修补到了\u xml
?是的,我在模块中把
修补到了\u xml
。好吧,那你的修补程序看起来像什么?