190 likes | 285 Views
XML and Ruby on Rails. Jennifer Andrews LIS 531F April 25,2007. Strengths of databases. Effective searching Efficient data storage (no redundancy) Scalable Reliable Good security features Been around a long time Part of the business structure. Strengths of XML. Human readable
E N D
XML and Ruby on Rails Jennifer Andrews LIS 531F April 25,2007
Strengths of databases • Effective searching • Efficient data storage (no redundancy) • Scalable • Reliable • Good security features • Been around a long time • Part of the business structure
Strengths of XML • Human readable • Open standard, not tied to a platform • Structure part of document facilitates transfer and sharing of information • Flexible • Becoming more important with increase of information sharing across businesses and applications
Relational Database • Stores data in tables made up of rows and columns • Each row represents a record • Order of records irrelevant • Many tables connected by “keys” • Can express complex relationships between tables
XML • Hierarchical • Harder to express complex relationships • Order of data important • Preservation of order?
Ruby on Rails • Based on Ruby • Web based database applications • Basic structure built into Rails • All pieces of the application interact in standard way • Advantage? Easy and speedy development of applications • OPEN SOURCE
Architecture • MVC or Model, View, Controller • Controller = conductor • Model = data handling, enforces “rules” • Views = HTML, interface for interaction with user, but only displays, never handles data
New material Fiber Weight Brand Color Back
Now what? • Create an XML document • Create view or “template” saved as .rxml • One small piece of code in the controller • Point browser to that view • And …..
Code to generate XML resides in template xml.instruct! :xml, :version=>"1.0" xml.channel { for m in @materials xml.material do xml.title(m.fiber) xml.description(m.weight) xml.brand(m.brand) xml.color(m.color) end end }
How does it happen? • MAGIC! • A piece ofRuby code called Builder • Takes what is after the xml. and turns it into a tag • xml.description becomes <description> • can include attibutes, too • xml.price(p.price, currency => “USD”) becomes <price currency=”USD”>50.00</price>.
Real Life Application • Rails app collecting orders for books • Part of that process – collecting names, addresses • Marketing department wants names of all who bought a certain book (in XML) to feed into a another program they have.
Another way • Autogenerate through command called to_xml • Dumps everything • No control over order of elements • Possible to add code so if a request comes for HTML – that is what’s returned, if the request is for XML, that is what is returned
Bits and pieces • Can you use XML to input data into RonR? • Installing RonR on computer • Locomotive • 2 tutorials • Put your XML knowledge to use • Start simple, ride the rails, and be amazed