开发者

NameError: uninitialized constant ActiveRecord::Associations::Builder::XMLMarkup

I开发者_C百科 found a post with a headline quite similar to this one, but it didn't give me the answer I was looking for. I am trying to use builder inside a model. The code looks something like this:

require 'builder'

class Document < ActiveRecord::Base
...
  def create_xml
  xml = Builder::XmlMarkup.new( :indent => 2)
  ...
  end
...
end

When I try to execute this code, I get the following error:

NameError: uninitialized constant ActiveRecord::Associations::Builder::XMLMarkup

But, when I try the same thing within the rails console, everything works just fine.

Am I missing something? Any help would be much appreciated.


Found the answer.

You have to append Builder to the rootlevel, like this:

xml = ::Builder::XmlMarkup.new( :indent => 2 )
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜