Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 622
klaffenboeck Avatar asked Sep 15 '11 03:09

klaffenboeck


1 Answers

Found the answer.

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

xml = ::Builder::XmlMarkup.new( :indent => 2 )
like image 139
klaffenboeck Avatar answered Nov 13 '22 07:11

klaffenboeck