Guest User

Untitled

a guest
Apr 13th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. require 'rubygems'
  2. require 'active_record'
  3. require 'builder'
  4.  
  5. ActiveRecord::Base.establish_connection({
  6. :adapter => 'mysql',
  7. :database => 'gandc',
  8. :host => 'localhost',
  9. :username => 'noodl',
  10. :password => 'xxx'
  11. })
  12.  
  13. class Book < ActiveRecord::Base
  14. set_primary_key :entryID
  15. has_many :components, :foreign_key => 'entryID'
  16. end
  17.  
  18. class Component < ActiveRecord::Base
  19. set_primary_key :componentsID
  20. belongs_to :book, :foreign_key => "entryID"
  21. end
  22.  
  23. buffer = ""
  24. xml = Builder::XmlMarkup.new(:target => buffer, :indent => 2)
  25. xml.instruct!
  26.  
  27. Component.find(:all,
  28. :conditions => 'readyOmitDefer = 1',
  29. :limit => 10
  30. ).each do |comp|
  31.  
  32. next unless comp.book
  33.  
  34. xml.doc {
  35. xml.field(comp.entryID, :name => :entryID)
  36. xml.field(comp.book.title, :name => :title)
  37. # ... and so on
  38. }
  39. end
  40.  
  41. puts buffer
Add Comment
Please, Sign In to add comment