views:

79

answers:

1

I'm trying to use delayed_job to update a remote database via xml

In my lib folder I put a file with a class that should do a render_to_text with template.xml.builder, but I get:

undefined method `render_to_string' for #...

What am I doing wrong?

+1  A: 

render_to_string is defined in ActionController::Base. Since the class/module is defined outside the scope of the Rails controllers the function is not available.

You are going to have to manually render the file. I don't know what you are using for your templates (ERB, Haml, etc.). But you are going to have load the template and parse it yourself.

So if ERB, something like this:

require 'erb'

x = 42
template = ERB.new <<-EOF
  The value of x is: <%= x %>
EOF
puts template.result(binding)

You will have to open the template file and send the contents to ERB.new, but that an exercise left for you. Here are the docs for ERB.

That's the general idea.

Tony Fontenot