<?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>Web Development Advice and Tips &#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>SmartLogic Solutions Blog</description>
	<lastBuildDate>Thu, 09 May 2013 14:52:04 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.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[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[skip_relative_url_root]]></category>
		<category><![CDATA[url_for]]></category>

		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=193</guid>
		<description><![CDATA[<p>Abusing the rails url_helpers through lazy coding may create problems when overriding the url_helper.<div class="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2012/02/21/using-rspec-macros-and-metadata/"     class="crp_title">Using RSpec Macros and Metadata</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/12/12/api-versioning-3-ways-to-architect-your-api-to-handle-versioned-requests/"     class="crp_title">API Versioning: 3 Ways to Architect Your API to Handle&hellip;</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/12/05/how-to-save-time-when-reformatting-dates-in-vim/"     class="crp_title">Vim Tip: How to Reformat Dates in 7 Steps</a></li><li><a href="http://blog.smartlogicsolutions.com/2013/04/02/ios-development-dtattributedtextview-instead-of-uiwebview/"     class="crp_title">iOS Development with DTCoreText: Rendering HTML as App&hellip;</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/10/08/testing-ajax-with-testunit/"     class="crp_title">Testing AJAX with Test::Unit</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/" rel="nofollow">Contextual Related Posts</a></li></ul></div></p><p>The post <a href="http://blog.smartlogicsolutions.com/2008/08/26/loosely-defined-link_to-may-cause-problems-when-overriding-url_helper/">Loosely defined link_to may cause problems when overriding url_helper</a> appeared first on <a href="http://blog.smartlogicsolutions.com">Web Development Advice and Tips</a>.</p>]]></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 class="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2012/02/21/using-rspec-macros-and-metadata/"     class="crp_title">Using RSpec Macros and Metadata</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/12/12/api-versioning-3-ways-to-architect-your-api-to-handle-versioned-requests/"     class="crp_title">API Versioning: 3 Ways to Architect Your API to Handle&hellip;</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/12/05/how-to-save-time-when-reformatting-dates-in-vim/"     class="crp_title">Vim Tip: How to Reformat Dates in 7 Steps</a></li><li><a href="http://blog.smartlogicsolutions.com/2013/04/02/ios-development-dtattributedtextview-instead-of-uiwebview/"     class="crp_title">iOS Development with DTCoreText: Rendering HTML as App&hellip;</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/10/08/testing-ajax-with-testunit/"     class="crp_title">Testing AJAX with Test::Unit</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/" rel="nofollow">Contextual Related Posts</a></li></ul></div><p>The post <a href="http://blog.smartlogicsolutions.com/2008/08/26/loosely-defined-link_to-may-cause-problems-when-overriding-url_helper/">Loosely defined link_to may cause problems when overriding url_helper</a> appeared first on <a href="http://blog.smartlogicsolutions.com">Web Development Advice and Tips</a>.</p>]]></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>

		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/2008/06/05/mapresources-and-custom-nested-routes/</guid>
		<description><![CDATA[<p>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] [...]<div class="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2012/12/12/api-versioning-3-ways-to-architect-your-api-to-handle-versioned-requests/"     class="crp_title">API Versioning: 3 Ways to Architect Your API to Handle&hellip;</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/08/28/api-planning-and-proceeding-tell-me-what-youre-working-with/"     class="crp_title">API Planning and Proceeding: Tell Me What You’re Working&hellip;</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/09/17/rest-fest-3-things-i-learned/"     class="crp_title">REST Fest &#8211; 3 Things I Learned</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/08/30/nicks-highlights-from-lone-star-ruby-conf/"     class="crp_title">Nick&#8217;s Highlights from Lone Star Ruby Conf</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/02/21/using-rspec-macros-and-metadata/"     class="crp_title">Using RSpec Macros and Metadata</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/" rel="nofollow">Contextual Related Posts</a></li></ul></div></p><p>The post <a href="http://blog.smartlogicsolutions.com/2008/06/05/mapresources-and-custom-nested-routes/">map.resources and custom nested routes</a> appeared first on <a href="http://blog.smartlogicsolutions.com">Web Development Advice and Tips</a>.</p>]]></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 class="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2012/12/12/api-versioning-3-ways-to-architect-your-api-to-handle-versioned-requests/"     class="crp_title">API Versioning: 3 Ways to Architect Your API to Handle&hellip;</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/08/28/api-planning-and-proceeding-tell-me-what-youre-working-with/"     class="crp_title">API Planning and Proceeding: Tell Me What You’re Working&hellip;</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/09/17/rest-fest-3-things-i-learned/"     class="crp_title">REST Fest &#8211; 3 Things I Learned</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/08/30/nicks-highlights-from-lone-star-ruby-conf/"     class="crp_title">Nick&#8217;s Highlights from Lone Star Ruby Conf</a></li><li><a href="http://blog.smartlogicsolutions.com/2012/02/21/using-rspec-macros-and-metadata/"     class="crp_title">Using RSpec Macros and Metadata</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/" rel="nofollow">Contextual Related Posts</a></li></ul></div><p>The post <a href="http://blog.smartlogicsolutions.com/2008/06/05/mapresources-and-custom-nested-routes/">map.resources and custom nested routes</a> appeared first on <a href="http://blog.smartlogicsolutions.com">Web Development Advice and Tips</a>.</p>]]></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>
