My Snippets

Reading a local Rails file

begin
	f = File.open("#{RAILS_ROOT}/public/#{@mediaitem.path}","r")
	textcontents = f.read
ensure
	f.close
end
return textcontents

August 31st, 2008 Posted by | ruby | no comments
[]

Get last element in an XML element list

XML:
  1. <car>
  2.   <wheel name="frontleft">FL</wheel>
  3.   <wheel name="frontright">FR</wheel>
  4.   <wheel name="backleft">BL</wheel>
  5.   <wheel name="backright">BR</wheel>
  6. </car>

xpath: //wheel[last()=position()]
=>

XML:
  1. <wheel name="backright">BR</wheel>

August 29th, 2008 Posted by | xml | no comments
[]