<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Unterbahn &#187; rails</title>
	<atom:link href="http://unterbahn.com/tag/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://unterbahn.com</link>
	<description></description>
	<lastBuildDate>Wed, 01 Feb 2012 17:26:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.4</generator>
		<item>
		<title>Serving &#8216;OSM-JSON&#8217; alongside XML from the OpenStreetMap Rails port</title>
		<link>http://unterbahn.com/2009/07/serving-osm-json-alongside-xml-from-the-openstreetmap-rails-port/</link>
		<comments>http://unterbahn.com/2009/07/serving-osm-json-alongside-xml-from-the-openstreetmap-rails-port/#comments</comments>
		<pubDate>Fri, 31 Jul 2009 16:57:39 +0000</pubDate>
		<dc:creator>Jeffrey Warren</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[cartagen]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[mapping]]></category>
		<category><![CDATA[openstreetmap]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://unterbahn.com/?p=765</guid>
		<description><![CDATA[OpenStreetMap.org&#8216;s RESTful API allows anyone to access data on their continually growing collaborative map of the world&#8230; in XML. This is great for most applications, but if you&#8217;re working in JavaScript (as we are), XML might as well be greek. We need JSON. To offer OSM-JSON along with of OSM-XML, we added a route to [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://openstreetmap.org">OpenStreetMap.org</a>&#8216;s RESTful API allows anyone to access data on their continually growing collaborative map of the world&#8230; in XML. This is great for most applications, but if you&#8217;re working in JavaScript (as <a href="http://cartagen.org">we are</a>), XML might as well be greek. We need JSON.</p>
<p>To offer OSM-JSON along with of OSM-XML, we added a route to accept a &#8220;.format&#8221; suffix, and split up the render call based on the params[:format] part of the route:</p>
<pre>
# /config/routes.rb:46-50

map.connect "api/#{API_VERSION}/geohash/:geohash.:format", :controller => 'api', :action => 'geohash'
map.connect "api/#{API_VERSION}/geohash/:geohash", :controller => 'api', :action => 'geohash'

map.connect "api/#{API_VERSION}/map.:format", :controller => 'api', :action => 'map'
map.connect "api/#{API_VERSION}/map", :controller => 'api', :action => 'map'
</pre>
<p>Notice we also added a &#8216;geohash&#8217; route. Whereas the /map call requires a bbox parameter (&#8216;bbox=min_lon,min_lat,max_lon,max_lat&#8217;), we can use a <a href="http://en.wikipedia.org/wiki/Geohash">geohash</a> (<a href="http://github.com/davetroy/geohash-js/tree/master">Geohash in JavaScript</a>, <a href="http://github.com/davetroy/geohash/tree/master">Geohash in Rails</a>) which defines a bounding box as a sequence of letters and numbers. This fits Cartagen&#8217;s needs well, and since it doesn&#8217;t require any parameters, we can page cache it in Rails. (Remember that page caching bypasses Rails entirely, letting Apache handle these cached files at high speed &#8211; that saved us when we were on BoingBoing).</p>
<p><span id="more-765"></span></p>
<p>We then modify the api_controller to respond_to either <b>.xml</b> or <b>.json</b>:</p>
<pre>
# /app/controllers/api_controller.rb:284-287

respond_to do |format|
  format.xml  { render :text => doc.to_s, :content_type => "text/xml" }
  format.json  { render :json => {'osm' => doc} }
end
</pre>
<p>However, to pack up our objects into JSON properly, we also had to modify the map method further, for nodes, ways, and relations:</p>
<pre>
# /app/controllers/api_controller.rb:186-190
if params[:format] == 'json'
  doc['node'] << node.to_json_obj
else
  doc.root << node.to_xml_node(changeset_cache, user_display_name_cache)
end
</pre>
<p>The above was repeated for ways and relations, lines 202 and 270. </p>
<p>Then, we added a geohash method to catch our new geohash route:</p>
<pre>
# /app/controllers/api_controller.rb:76-80
def geohash
  _bbox = GeoHash.decode_bbox(params[:geohash])
  params['bbox'] = _bbox[0][1].to_s+','+_bbox[0][0].to_s+','+_bbox[1][1].to_s+','+_bbox[1][0].to_s
  map
end
</pre>
<p>Finally, we cloned the to_json_obj methods in /models/node.rb, /models/way.rb, and /models/relation.rb, which was pretty minor – we just restructured how they're packed up.</p>
<p>As HTML5 and the new generation of JavaScript interpreters transform the web, I expect we'll see a lot more APIs implemented in JSON as well as XML, and I'd be happy to help anyone with an OSM Rails port get this set up. For the time being, feel free to use our OSM API (with JSON!) at http://cartagen.org/api/0.6/...</p>
<p><em>Download the modified code here: <a href="http://unterbahn.com/wp-content/uploads/2009/07/openstreetmap.zip">openstreetmap.zip</a> <br />(based on OSM revision 15115)</em></p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://unterbahn.com/2009/04/geohash-stickers-idea/" rel="bookmark" class="crp_title">Geohash-stickers idea</a></li><li><a href="http://unterbahn.com/2009/11/metric-dimensions-of-geohash-partitions-at-the-equator/" rel="bookmark" class="crp_title">Metric dimensions of geohash partitions at the equator</a></li><li><a href="http://unterbahn.com/2009/09/native-json-parsing-hooray/" rel="bookmark" class="crp_title">Native JSON parsing&#8230; hooray, with benchmarks!</a></li><li><a href="http://unterbahn.com/2009/10/composition-of-a-openstreetmap-api-responses/" rel="bookmark" class="crp_title">Composition of a typical OpenStreetMap API response</a></li><li><a href="http://unterbahn.com/2009/08/adjustment-for-rails-find-method/" rel="bookmark" class="crp_title">Adjustment for Rails &#8216;find()&#8217; method</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://unterbahn.com/2009/07/serving-osm-json-alongside-xml-from-the-openstreetmap-rails-port/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Rails schema for FrontlineSMS</title>
		<link>http://unterbahn.com/2009/06/rails-schema-for-frontlinesms/</link>
		<comments>http://unterbahn.com/2009/06/rails-schema-for-frontlinesms/#comments</comments>
		<pubDate>Thu, 11 Jun 2009 17:38:13 +0000</pubDate>
		<dc:creator>Jeffrey Warren</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[cartagen]]></category>
		<category><![CDATA[frontlinesms]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[sms]]></category>

		<guid isPermaLink="false">http://unterbahn.com/?p=682</guid>
		<description><![CDATA[For those of you trying to write Rails applications around a FrontlineSMS database in MySQL: rails-frontlinesms.txt Related Posts:Batch importing text messages from Twitter in RailsWoW Google MapBeautiful maps from the RETREAT projectMap Warper &#8211; Rectifying mapsFull-sized papercraft]]></description>
			<content:encoded><![CDATA[<p><a href="http://unterbahn.com/wp-content/uploads/2009/06/Picture-2.png"><img src="http://unterbahn.com/wp-content/uploads/2009/06/Picture-2.png" alt="FrontlineSMS" title="Picture 2" width="423" height="256" class="alignnone size-full wp-image-683" /></a></p>
<p>For those of you trying to write Rails applications around a <a href="http://www.frontlinesms.com/">FrontlineSMS</a> database in MySQL:</p>
<p><a href='http://unterbahn.com/wp-content/uploads/2009/06/rails-frontlinesms.txt'>rails-frontlinesms.txt</a></p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://unterbahn.com/2009/03/batch-importing-text-messages-from-twitter-in-rails/" rel="bookmark" class="crp_title">Batch importing text messages from Twitter in Rails</a></li><li><a href="http://unterbahn.com/2009/08/wow-google-map/" rel="bookmark" class="crp_title">WoW Google Map</a></li><li><a href="http://unterbahn.com/2009/09/beautiful-maps-from-the-retreat-project/" rel="bookmark" class="crp_title">Beautiful maps from the RETREAT project</a></li><li><a href="http://unterbahn.com/2009/10/map-warper-rectifying-maps/" rel="bookmark" class="crp_title">Map Warper &#8211; Rectifying maps</a></li><li><a href="http://unterbahn.com/2009/11/full-sized-papercraft/" rel="bookmark" class="crp_title">Full-sized papercraft</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://unterbahn.com/2009/06/rails-schema-for-frontlinesms/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sending and receiving text messages in Rails with Twitter</title>
		<link>http://unterbahn.com/2009/03/connecting-a-ruby-on-rails-application-to-twitter/</link>
		<comments>http://unterbahn.com/2009/03/connecting-a-ruby-on-rails-application-to-twitter/#comments</comments>
		<pubDate>Mon, 09 Mar 2009 15:27:50 +0000</pubDate>
		<dc:creator>Jeffrey Warren</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[nocollision]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[whooz]]></category>

		<guid isPermaLink="false">http://unterbahn.com/?p=145</guid>
		<description><![CDATA[In this tutorial I cover how to set up a basic Ruby on Rails 2.2.2 application and how to connect it to the Twitter API. Then I demonstrate receiving and sending Tweets, i.e. text messages through Twitter. I&#8217;ve also shared the code in Google Code. WHOOZ Tutorial: Sending and receiving text messages in Rails with [...]]]></description>
			<content:encoded><![CDATA[<p>In this tutorial I cover how to set up a basic Ruby on Rails 2.2.2 application and how to connect it to the Twitter API. Then I demonstrate receiving and sending Tweets, i.e. text messages through Twitter. I&#8217;ve also shared the code in <a href="http://code.google.com/p/whooz/">Google Code</a>.</p>
<p><object width="500" height="313"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=3541782&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=3541782&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=ffffff&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="500" height="313"></embed></object><br /><a href="http://vimeo.com/3541782">WHOOZ Tutorial: Sending and receiving text messages in Rails with Twitter</a></p>
<p>Download the code for this tutorial here: <a href="http://unterbahn.com/wp-content/uploads/2009/03/whooz-twitter-integration.zip">whooz-twittter-integration.zip</a> (LGPL 3.0)</p>
<p>This code requires <a href="http://rubyonrails.org">Rails 2</a> &#8211; if you have OS X 10.5, it ships with 1.2; you can upgrade with the commands <code>sudo gem update --system</code> and <code>sudo gem install rails</code></p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://unterbahn.com/2009/03/batch-importing-text-messages-from-twitter-in-rails/" rel="bookmark" class="crp_title">Batch importing text messages from Twitter in Rails</a></li><li><a href="http://unterbahn.com/2009/04/parsing-out-keyvalue-pairs-from-text-messages-and-geocoding-them/" rel="bookmark" class="crp_title">Parsing out key:value pairs from text messages and geocoding them</a></li><li><a href="http://unterbahn.com/2009/04/manhattan-mapped-in-cartagen-htmljavascript-with-gss/" rel="bookmark" class="crp_title">Manhattan mapped in Cartagen html/javascript with gss</a></li><li><a href="http://unterbahn.com/2009/09/idea-connect-paper-video-camera-to-cell-audio-connection/" rel="bookmark" class="crp_title">Idea: connect paper video camera to cell audio connection</a></li><li><a href="http://unterbahn.com/2008/11/video-2/" rel="bookmark" class="crp_title">Mapwar presentation</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://unterbahn.com/2009/03/connecting-a-ruby-on-rails-application-to-twitter/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

