<?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>Sean&#039;s Blog &#187; urls</title>
	<atom:link href="http://seanbehan.com/tag/urls/feed/" rel="self" type="application/rss+xml" />
	<link>http://seanbehan.com</link>
	<description>Web Programming, Ruby on Rails, Wordpress, PHP from Burlington, Vermont</description>
	<lastBuildDate>Wed, 18 Jan 2012 21:44:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Scope Routes/URLs By Username (like Twitter) in Your Rails Application</title>
		<link>http://seanbehan.com/posts/scope-routesurls-by-username-like-twitter-in-your-rails-application/</link>
		<comments>http://seanbehan.com/posts/scope-routesurls-by-username-like-twitter-in-your-rails-application/#comments</comments>
		<pubDate>Sun, 22 Aug 2010 21:09:22 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[link_to]]></category>
		<category><![CDATA[routes]]></category>
		<category><![CDATA[scoping]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[urls]]></category>
		<category><![CDATA[usernames]]></category>
		<category><![CDATA[views]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=1135</guid>
		<description><![CDATA[There are a few things that need to be taken care of before you can get this to work. The first thing (although, any of the following steps can be done in any order) to take care of involves your User model. You need to override the to_param method, so that Rails will appropriately use [...]]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fseanbehan.com%2Fposts%2Fscope-routesurls-by-username-like-twitter-in-your-rails-application%2F&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Scope Routes/URLs By Username (like Twitter) in Your Rails Application" data-url="http://seanbehan.com/posts/scope-routesurls-by-username-like-twitter-in-your-rails-application/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>There are a few things that need to be taken care of before you can get this to work. The first thing (although, any of the following steps can be done in any order) to take care of involves your User model. You need to override the to_param method, so that Rails will appropriately use the username attribute rather than user_id when constructing paths. </p>
<pre class="wp-code-highlight prettyprint">
#in app/models/user.rb
def to_param
  &quot;#{self.username}&quot;
end
</pre>
<p>Next we move onto routing our resources. Here it gets a little tricky because Rails is building paths for us. Remeber, you can get a list of all currently defined routes in your application by running the routes rake task</p>
<pre class="wp-code-highlight prettyprint">
rake routes
</pre>
<p>We need to set the path_prefix option on any of our resources we want scoped by the username. For instance, in this example, I have set up a Status model and statuses_controller, whose urls shall be scoped by the username. You can apply the path_prefix to any number of other resources in your routes config file. They symbol used is arbitrary, but will be made available in the params hash,  in this case params[:user_id]. You also need to exclude the show action on your users resources declaration. The reason is that, otherwise, Rails will include the controller name in the path like /users/username, which doesn&#8217;t look as clean as just /username. You then need to redefine this route explicitly (last line in the routes config shown here). </p>
<pre class="wp-code-highlight prettyprint">
#in app/config/routes.rb
map.resources :statuses,   :path_prefix =&amp;gt; '/:user_id'
map.resources :users,     :except =&amp;gt; [:show]
map.user '/:username' :controller =&amp;gt; 'users', :action =&amp;gt; 'show'
</pre>
<p>Finally, you get to call these routes in your views or use them in your controllers. You use the same link_to, url_for methods to generate paths. When constructing the resources you have setup with the path_prefix declartion, remember you need the user model as the first argument, followed by said resource. </p>
<pre class="wp-code-highlight prettyprint">
&amp;lt;%= link_to(status.title, status_path(status.user,status) %&amp;gt;
# or in a controller
redirect_to status_path( status.user, status )
</pre>
<p>That&#8217;s pretty much it. If anyone has another way of doing this let me know! </p>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/posts/scope-routesurls-by-username-like-twitter-in-your-rails-application/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>How to Use Pretty URLs with Rails will_paginate Plugin</title>
		<link>http://seanbehan.com/ruby-on-rails/how-to-use-pretty-urls-with-rails-will_paginate-plugin/</link>
		<comments>http://seanbehan.com/ruby-on-rails/how-to-use-pretty-urls-with-rails-will_paginate-plugin/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 01:43:54 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[routes]]></category>
		<category><![CDATA[urls]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=321</guid>
		<description><![CDATA[The will_paginate plugin for Rails uses a key/value assignment like ?page=2, rather than the pretty url formats such as /page/2 &#8230; This is because url generation and mapping are handled by the routes.rb file. You&#8217;ll need to modify the file so that rails knows what to do with request that match the pattern. Make sure [...]]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fseanbehan.com%2Fruby-on-rails%2Fhow-to-use-pretty-urls-with-rails-will_paginate-plugin%2F&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="How to Use Pretty URLs with Rails will_paginate Plugin" data-url="http://seanbehan.com/ruby-on-rails/how-to-use-pretty-urls-with-rails-will_paginate-plugin/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>The will_paginate plugin for Rails uses a key/value assignment like ?page=2, rather than the pretty url formats such as /page/2 &#8230; This is because url generation and mapping are handled by the routes.rb file. You&#8217;ll need to modify the file so that rails knows what to do with request that match the pattern. Make sure to put the custom (map.connect) route before the normal restful routes (map.resources)</p>
<pre class="wp-code-highlight prettyprint">
map.connect '/topics/:id/page/:page', :controller =&gt; 'topics', :action =&gt; 'show'
map.resources :topics
</pre>
<p>Internally will_paginate uses the url_for method so Rails will now know how to construct your urls in a pretty way. I got most of this info from this discusson http://groups.google.com/group/will_paginate/browse_thread/thread/d0142b512cfca9d5?pli=1</p>
<p>There is nothing wrong leaving the default behavior alone and looking at the &#8216;ugly&#8217; key/value pairs in the address bar. However, if you take advantage of page caching in rails, you&#8217;ll need to do this anyway. Page caching in rails ignore extra parameters, any info before/after the &#8220;?&#8221; and &#8220;&#038;&#8221; symbols. There will be no difference from /topics/2?page=1 and /topics/2?page=100 in your cache. And since most likely the content will be very different on these two pages, you&#8217;ll need to have pretty urls so that page caching will save topics/2/page/1.html and topics/2/page/100.html as two different resources!</p>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/ruby-on-rails/how-to-use-pretty-urls-with-rails-will_paginate-plugin/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

