<?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>SmartLogic Solutions Blog &#187; Routing</title>
	<atom:link href="http://blog.smartlogicsolutions.com/category/routing/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.smartlogicsolutions.com</link>
	<description>News and updates from the people at SmartLogic Solutions</description>
	<lastBuildDate>Tue, 30 Nov 2010 21:39:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Loosely defined link_to may cause problems when overriding url_helper</title>
		<link>http://blog.smartlogicsolutions.com/2008/08/26/loosely-defined-link_to-may-cause-problems-when-overriding-url_helper/</link>
		<comments>http://blog.smartlogicsolutions.com/2008/08/26/loosely-defined-link_to-may-cause-problems-when-overriding-url_helper/#comments</comments>
		<pubDate>Tue, 26 Aug 2008 21:27:22 +0000</pubDate>
		<dc:creator>Glenn Gentzke</dc:creator>
				<category><![CDATA[Glenn Gentzke]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Routing]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[argumenterror]]></category>
		<category><![CDATA[default_url_options]]></category>
		<category><![CDATA[helper]]></category>
		<category><![CDATA[links]]></category>
		<category><![CDATA[link_to]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[skip_relative_url_root]]></category>
		<category><![CDATA[url_for]]></category>

		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=193</guid>
		<description><![CDATA[Abusing the rails url_helpers through lazy coding may create problems when overriding the url_helper.]]></description>
			<content:encoded><![CDATA[<p><strong>OR &#8220;Beware of pick pockets and loose link_to&#8217;s&#8221;</strong></p>
<p>I hope most rails dev&#8217;s out there take advantage of RESTful routes and the url-generating helpers so readily available these days and actually <em>enjoy</em> them.  But for some of you who are lucky enough to inherit a legacy app (you know, 1 year olds) or for whatever reason encounter loosely defined link_to&#8217;s [exemplified below], you can easily update the code to avoid some gotchas.</p>
<p>This is what I consider a loosely defined link_to:</p>
<p><code>link_to 'Destroy', <strong>some_record</strong>, :confirm => 'Are you sure?', :method => :delete</code></p>
<p>It lacks parentheses, option grouping, and most importantly, expects the helpers to generate a specific kind of link (in this case a destroy action) from <strong>just the record itself</strong>.  Now, rails is pretty smart these days and will probably generate the correct link without a hiccup if your app isn&#8217;t employing a custom <strong>RAILS_RELATIVE_URL_ROOT</strong>, or setting <strong>skip_relative_url_root => false</strong>.</p>
<p>Well, my latest app is.  And this is how that loosely defined link_to renders:</p>
<blockquote><p><strong>ArgumentError in Controller#action</strong><br />
wrong number of arguments (0 for 1)</p></blockquote>
<p>The stack trace will provide evidence that some thing&#8217;s a mess in url_for related to the default_url_options, defined in application.rb (or elsewhere).  Rails&#8217; helpers cannot correctly produce a url due to lazy linking.</p>
<p>So, make your code more readable and keep the helpers happy and define your link_to&#8217;s like this:</p>
<p><code>link_to ( 'Destroy', <strong>record_path(some_record)</strong>, :confirm => 'Are you sure?', :method => :delete )</code></p>
<p>Refresh that error page and voila! Happy links again!  Stricter coders may even group the options with curlies, and that doesn&#8217;t hurt either.</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2009/06/04/mount-options-to-improve-ext4-file-system-performance/" rel="bookmark" class="crp_title">Mount options to improve ext4 file system performance</a></li><li><a href="http://blog.smartlogicsolutions.com/2007/06/12/struts-11-problems-with-logiciterate-tags-and-cannot-find-bean-xxx-under-any-scope/" rel="bookmark" class="crp_title">Struts 1.1: Problems with logic:iterate tags and &#8220;Cannot find bean XXX under any scope&#8221;</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/07/07/i-cant-upgrade-rubygems-from-111-to-120-on-ubuntu/" rel="bookmark" class="crp_title">I can&#8217;t upgrade RubyGems from 1.1.1 to 1.2.0 on Ubuntu</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/06/13/ruby-on-rails-polymorphic-association-benchmarks/" rel="bookmark" class="crp_title">Ruby on Rails Polymorphic Association Benchmarks</a></li><li><a href="http://blog.smartlogicsolutions.com/2009/09/20/timecop-0-3-0-released/" rel="bookmark" class="crp_title">Timecop 0.3.0 Released</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.smartlogicsolutions.com/2008/08/26/loosely-defined-link_to-may-cause-problems-when-overriding-url_helper/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>map.resources and custom nested routes</title>
		<link>http://blog.smartlogicsolutions.com/2008/06/05/mapresources-and-custom-nested-routes/</link>
		<comments>http://blog.smartlogicsolutions.com/2008/06/05/mapresources-and-custom-nested-routes/#comments</comments>
		<pubDate>Thu, 05 Jun 2008 19:25:21 +0000</pubDate>
		<dc:creator>Scott Davis</dc:creator>
				<category><![CDATA[Routing]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Scott Davis]]></category>

		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/2008/06/05/mapresources-and-custom-nested-routes/</guid>
		<description><![CDATA[I encountered an error in rails trying to create a nested route in rails 2.x map.import_time_cards 'users/:user_id/time_cards/import', :controller => 'time_cards', :action => 'import' Wasn&#8217;t setting up a route for users because this route was being setup automatically and overwritten by: map.resources :users, :has_many => [:notes, :addresses, :expenses, :time_cards] , :collection => [:login, :logout, :disable, :enable] [...]]]></description>
			<content:encoded><![CDATA[<p>I encountered an error in rails trying to create a nested route in rails 2.x<br />
<code><br />
map.import_time_cards 'users/:user_id/time_cards/import',<br />
  :controller => 'time_cards',<br />
  :action => 'import'<br />
</code><br />
Wasn&#8217;t setting up a route for users because this route was being setup automatically and overwritten by:<br />
<code><br />
map.resources :users,<br />
  :has_many => [:notes, :addresses, :expenses, :time_cards] ,<br />
  :collection => [:login, :logout, :disable, :enable]<br />
</code><br />
So after digging around on the rails <a href="http://api.rubyonrails.org">api</a> I discovered that map.resources takes a block so my solution to this problem was :<br />
<code><br />
map.resources(:users,<br />
  :has_many => [:notes, :addresses, :expenses] ,<br />
  :collection => [:login, :logout, :disable, :enable]) do |user|<br />
    user.resources :time_cards, :collection => [:import]<br />
  end<br />
</code><br />
By using a block this tells rails to include route to &#8216;users/1/time_cards/import&#8217; instead of appending import as the id for the show route.</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2008/07/21/advanced-model-based-searches-in-rails/" rel="bookmark" class="crp_title">Advanced Model Based searches in rails</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/05/22/spotcrime-iphone-application-gets-techcrunched/" rel="bookmark" class="crp_title">SpotCrime iPhone Application gets TechCrunched</a></li><li><a href="http://blog.smartlogicsolutions.com/2009/05/26/including-external-rake-files-in-your-projects-rakefile-keep-your-rake-tasks-organized/" rel="bookmark" class="crp_title">Including external .rake files in your project&#8217;s Rakefile &#8212; keep your rake tasks organized!</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/05/16/flash-player-10-astro-flex-sdk-compile/" rel="bookmark" class="crp_title">Flash Player 10 (&#8220;Astro&#8221;) Prerelease and Flex SDK Build Available to Compile Flash Player 10 Content</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/10/28/faking-a-will-paginate-collection-on-an-active-resource-model/" rel="bookmark" class="crp_title">Faking a Will Paginate Collection on an Active Resource model</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.smartlogicsolutions.com/2008/06/05/mapresources-and-custom-nested-routes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

