<?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>a work on process &#187; activeresource</title>
	<atom:link href="http://jystewart.net/process/tag/activeresource/feed/" rel="self" type="application/rss+xml" />
	<link>http://jystewart.net/process</link>
	<description>notes from another web developer</description>
	<lastBuildDate>Tue, 27 Jul 2010 09:53:43 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Bus routes on Rails</title>
		<link>http://jystewart.net/process/2006/09/bus-routes-on-rails/</link>
		<comments>http://jystewart.net/process/2006/09/bus-routes-on-rails/#comments</comments>
		<pubDate>Mon, 25 Sep 2006 22:51:59 +0000</pubDate>
		<dc:creator>James Stewart</dc:creator>
				<category><![CDATA[Notes]]></category>
		<category><![CDATA[activeresource]]></category>
		<category><![CDATA[bus routes]]></category>
		<category><![CDATA[nested routes]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[screen scraping]]></category>
		<category><![CDATA[the rapid]]></category>
		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://jystewart.net/process/archives/2006/09/bus-routes-on-rails/</guid>
		<description><![CDATA[Following on from my previous entry about scraping bus route data from The Rapid&#8217;s website, and to begin to demonstrate the possibilities it opens up, I&#8217;ve set up a simple web service to provide route and stop data. It&#8217;s based on the new REST style from Edge Rails, and routes are scoped by city to <a href="http://jystewart.net/process/2006/09/bus-routes-on-rails/" class="more-link">More &#62;</a>]]></description>
			<content:encoded><![CDATA[<p>Following on from <a href="http://jystewart.net/process/archives/2006/09/scraping-grand-rapids-bus-routes/">my previous entry</a> about scraping bus route data from The Rapid&#8217;s website, and to begin to demonstrate the possibilities it opens up, I&#8217;ve set up a simple web service to provide route and stop data. It&#8217;s based on the new REST style from Edge Rails, and routes are scoped by city to allow for future expansion. To get data on Route 1, GET:</p>
<p><a href="http://projects.jystewart.net/buses/cities/1/routes/1">http://projects.jystewart.net/buses/cities/1/routes/1</a></p>
<p>To get a list of the stops within 1.5 miles of a given longitude and latitude, GET:</p>
<p>http://projects.jystewart.net/buses/cities/1/stops/?longitude=X&#038;latitude=Y&#038;distance=1.5</p>
<p>Using Edge Rails, setting up the application was remarkably simple. Three models, three controllers, appropriate use of respond_to blocks, and the right entries in config/routes.rb:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">map.<span style="color:#9900CC;">resources</span> <span style="color:#ff3333; font-weight:bold;">:cities</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>cities<span style="color:#006600; font-weight:bold;">|</span> 
  cities.<span style="color:#9900CC;">resources</span> <span style="color:#ff3333; font-weight:bold;">:stops</span>
  cities.<span style="color:#9900CC;">resources</span> <span style="color:#ff3333; font-weight:bold;">:routes</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>This was the first time I&#8217;ve used nested routes so it took a few minutes to work out the correct syntax for the link_to calls. When using nested routes like those above, you must declare first the ID of the city and then the ID of the stop or route, eg:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006600; font-weight:bold;">%</span>= link_to <span style="color:#996600;">'My Route'</span>, route_url<span style="color:#006600; font-weight:bold;">&#40;</span>city, route<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span></pre></div></div>

<p>I&#8217;m not making any guarantees about the long term availability of the service, but if anyone wants to make use of it, let me know and we can probably work something out. I&#8217;ll probably be making use of it myself.</p>
]]></content:encoded>
			<wfw:commentRss>http://jystewart.net/process/2006/09/bus-routes-on-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
