<?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>Cory O&#039;Daniel - These are just words &#187; display api</title>
	<atom:link href="http://coryodaniel.com/index.php/tag/display-api/feed/" rel="self" type="application/rss+xml" />
	<link>http://coryodaniel.com</link>
	<description>Software development, thoughts, and randomness</description>
	<lastBuildDate>Thu, 17 Nov 2011 21:18:05 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>DataMapper and Merb, sharing your errors via the merb display API.</title>
		<link>http://coryodaniel.com/index.php/2009/12/30/datamapper-and-merb-sharing-your-errors-via-the-merb-display-api/</link>
		<comments>http://coryodaniel.com/index.php/2009/12/30/datamapper-and-merb-sharing-your-errors-via-the-merb-display-api/#comments</comments>
		<pubDate>Thu, 31 Dec 2009 00:29:20 +0000</pubDate>
		<dc:creator>Cory O'Daniel</dc:creator>
				<category><![CDATA[Random]]></category>
		<category><![CDATA[RubyDevelopment]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[datamapper]]></category>
		<category><![CDATA[display api]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[merb]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://coryodaniel.com/?p=388</guid>
		<description><![CDATA[This is a quick little snippet.  At Vokle all of our products are built using our core API, which thanks to merb, was a piece of cake. The thing that sucks is sometimes we return objects as JSON via the display API and the "errors" are missing in the event that validation failed.  [...]]]></description>
			<content:encoded><![CDATA[<p>This is a quick little snippet.  At Vokle all of our products are built using our core API, which thanks to merb, was a piece of cake. The thing that sucks is sometimes we return objects as JSON via the display API and the "errors" are missing in the event that validation failed.  How to fix that?</p>
<p>Throw this somewhere:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">module</span> DataMapper
  <span style="color:#9966CC; font-weight:bold;">module</span> Validate
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">class</span> ValidationErrors
      <span style="color:#9966CC; font-weight:bold;">def</span> to_json
        <span style="color:#0066ff; font-weight:bold;">@errors</span>.<span style="color:#9900CC;">to_hash</span>.<span style="color:#9900CC;">to_json</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Now in your merb controllers, when you are displaying an object that may have errors:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> People <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">Merb::Controller</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> create<span style="color:#006600; font-weight:bold;">&#40;</span>person<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#008000; font-style:italic;">#... *SNIP* ...</span>
    display <span style="color:#0066ff; font-weight:bold;">@person</span>, <span style="color:#0000FF; font-weight:bold;">nil</span>, <span style="color:#006600; font-weight:bold;">&#123;</span>:methods <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:errors</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
    <span style="color:#008000; font-style:italic;">#... *SNIP* ...</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>And whatever is getting your data back in XML or JSON (yeah or YAML, right) will get the errors on your object as well.  Cool.</p>
<p>Yay, users give you invalid data. Congrats.</p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=DataMapper+and+Merb%2C+sharing+your+errors+via+the+merb+display+API.+http://bit.ly/6xoSlP" title="Post to Twitter"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-twitter-big2.png" alt="Post to Twitter" /></a> <a class="tt" href="http://digg.com/submit?url=http://coryodaniel.com/index.php/2009/12/30/datamapper-and-merb-sharing-your-errors-via-the-merb-display-api/&amp;title=DataMapper+and+Merb%2C+sharing+your+errors+via+the+merb+display+API." title="Post to Digg"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-digg-big2.png" alt="Post to Digg" /></a> <a class="tt" href="http://www.facebook.com/share.php?u=http://coryodaniel.com/index.php/2009/12/30/datamapper-and-merb-sharing-your-errors-via-the-merb-display-api/&amp;t=DataMapper+and+Merb%2C+sharing+your+errors+via+the+merb+display+API." title="Post to Facebook"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-facebook-big2.png" alt="Post to Facebook" /></a> <a class="tt" href="http://reddit.com/submit?url=http://coryodaniel.com/index.php/2009/12/30/datamapper-and-merb-sharing-your-errors-via-the-merb-display-api/&amp;title=DataMapper+and+Merb%2C+sharing+your+errors+via+the+merb+display+API." title="Post to Reddit"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-reddit-big2.png" alt="Post to Reddit" /></a> <a class="tt" href="http://stumbleupon.com/submit?url=http://coryodaniel.com/index.php/2009/12/30/datamapper-and-merb-sharing-your-errors-via-the-merb-display-api/&amp;title=DataMapper+and+Merb%2C+sharing+your+errors+via+the+merb+display+API." title="Post to StumbleUpon"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-su-big2.png" alt="Post to StumbleUpon" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://coryodaniel.com/index.php/2009/12/30/datamapper-and-merb-sharing-your-errors-via-the-merb-display-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

