12

I 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.

klaffenboeck
  • 6,297
  • 3
  • 23
  • 33

1 Answers1

39

Found the answer.

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

xml = ::Builder::XmlMarkup.new( :indent => 2 )
klaffenboeck
  • 6,297
  • 3
  • 23
  • 33
  • See the answer to this post: http://stackoverflow.com/questions/10482772/rubys-double-colon-operator-usage-differences – klaffenboeck Jan 08 '13 at 17:52