Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'rubygems'
- require 'active_record'
- require 'builder'
- ActiveRecord::Base.establish_connection({
- :adapter => 'mysql',
- :database => 'gandc',
- :host => 'localhost',
- :username => 'noodl',
- :password => 'xxx'
- })
- class Book < ActiveRecord::Base
- set_primary_key :entryID
- has_many :components, :foreign_key => 'entryID'
- end
- class Component < ActiveRecord::Base
- set_primary_key :componentsID
- belongs_to :book, :foreign_key => "entryID"
- end
- buffer = ""
- xml = Builder::XmlMarkup.new(:target => buffer, :indent => 2)
- xml.instruct!
- Component.find(:all,
- :conditions => 'readyOmitDefer = 1',
- :limit => 10
- ).each do |comp|
- next unless comp.book
- xml.doc {
- xml.field(comp.entryID, :name => :entryID)
- xml.field(comp.book.title, :name => :title)
- # ... and so on
- }
- end
- puts buffer
Add Comment
Please, Sign In to add comment