<?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>Merbist &#187; merb-assets</title>
	<atom:link href="http://merbist.com/tag/merb-assets/feed/" rel="self" type="application/rss+xml" />
	<link>http://merbist.com</link>
	<description>Random thoughts of a software developer</description>
	<lastBuildDate>Tue, 03 Jan 2012 02:34:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>problems with urls in Merb HEAD?</title>
		<link>http://merbist.com/2008/09/30/problems-with-urls-in-merb-head/</link>
		<comments>http://merbist.com/2008/09/30/problems-with-urls-in-merb-head/#comments</comments>
		<pubDate>Wed, 01 Oct 2008 06:24:29 +0000</pubDate>
		<dc:creator>Matt Aimonetti</dc:creator>
				<category><![CDATA[Misc]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[merb]]></category>
		<category><![CDATA[merb-assets]]></category>
		<category><![CDATA[router]]></category>

		<guid isPermaLink="false">http://merbist.com/?p=101</guid>
		<description><![CDATA[I actually run into a small problem when updated an older Merb app. Here was how my router looked like: Merb::Router.prepare do &#124;r&#124; r.resources :channels do &#124;channels&#124; channels.resources :shows do &#124;shows&#124; shows.resources :episodes end end end But after updating to the latest version of Merb, I got links looking like: http://localhost:4000/channels/#&#60;Channel:0x27b7300&#62;/shows The first thing to [...]]]></description>
			<content:encoded><![CDATA[<p>I actually run into a small problem when updated an older Merb app. Here was how my router looked like:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#6666ff; font-weight:bold;">Merb::Router</span>.<span style="color:#9900CC;">prepare</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>r<span style="color:#006600; font-weight:bold;">|</span>
  r.<span style="color:#9900CC;">resources</span> <span style="color:#ff3333; font-weight:bold;">:channels</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>channels<span style="color:#006600; font-weight:bold;">|</span>
    channels.<span style="color:#9900CC;">resources</span> <span style="color:#ff3333; font-weight:bold;">:shows</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>shows<span style="color:#006600; font-weight:bold;">|</span>
      shows.<span style="color:#9900CC;">resources</span> <span style="color:#ff3333; font-weight:bold;">:episodes</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></div></div>

<p>But after updating to the latest version of Merb, I got links looking like:</p>
<pre>http://localhost:4000/channels/#&lt;Channel:0x27b7300&gt;/shows</pre>
<p>The first thing to do is to read <a title="new router" href="http://github.com/carllerche/merb-core-enterprise-edition/wikis/whats-new-with-the-router" target="_blank">Carl&#8217;s wiki about the latest Router changes</a>.</p>
<p>Carl explains that things got cleaned up in the router code and my routes should now look like:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#6666ff; font-weight:bold;">Merb::Router</span>.<span style="color:#9900CC;">prepare</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>r<span style="color:#006600; font-weight:bold;">|</span>
  r.<span style="color:#9900CC;">resources</span> <span style="color:#ff3333; font-weight:bold;">:channels</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    resources <span style="color:#ff3333; font-weight:bold;">:shows</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>shows<span style="color:#006600; font-weight:bold;">|</span>
      resources <span style="color:#ff3333; font-weight:bold;">:episodes</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></div></div>

<p>However that won&#8217;t be enough..  You see my url used to look like that:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">url<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:channel_shows</span>, <span style="color:#ff3333; font-weight:bold;">:channel_id</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; channel<span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>Now I can simplify it to:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">url<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:channel_shows</span>, channel<span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>That still won&#8217;t fix the problem, since the real problem comes from the fact that I was on Merb HEAD but not DataMapper HEAD. Updating DM clears things up. That&#8217;s the price to pay to be on HEAD <img src='http://merbist.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>FYI the problem comes from the fact that DM doesn&#8217;t add a to_params method to its objects. Rails users might recognize that method used to convert an object into a string to create a route, something not really ORM agnostic and frowned upon by the DM/Merb teams.</p>
<p>Merb lets you specify the param to use for your routes using the identify method. Read <a title="new router" href="http://github.com/carllerche/merb-core-enterprise-edition/wikis/whats-new-with-the-router" target="_blank">Carl&#8217;s wiki page </a>for more cool stuff and see how to create some cool stuff like url slugs etc..</p>
<p>Note that even if you are using ActiveRecord, you&#8217;ll need to update merb_activerecord as the new identify rules were updated in the ORM plugins.</p>
]]></content:encoded>
			<wfw:commentRss>http://merbist.com/2008/09/30/problems-with-urls-in-merb-head/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

