Using builder rxml template in model

Im trying to decide the best way to implement an interface to
quickbooks using xml.
I have

class Timecard < ActiveRecord::Base
has_one :quickbook
after_create :quickbooks_add_timecard #this method calls

the thing is that I thought it was gonna work out great, I could put
all my xml templates in a views directory and have everything nice and
organized. The problem is that It seems like this operation should be
triggered from model callbacks, and I would lilke to put somethign like
this in the quickbook.rb model:

class Quickbook < ActiveRecord::Base
belongs_to :timecard
def add_timecard
request_xml = render_to_string :template =>

I see 3 options:
1.) move this callback logic out of the model and put it in the
controller in the first place.
2.) use Builder::XmlMarkup directly in the model, to generate an xml
request strig, loading the templates directly,
load “app/views/quickbooks/add_timecard”
3.) Figure out how to get a rendered template from within the model
(like shown above)

Option 3 seems the cleanest to me, it just goes against my normal
conventions of putting data model rules in the model. I’d like to
figure out how to do #3 in any case.

Any ideas?

Michael Fairhchild
The only problem with this is Im not sure

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs