<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: Vexfluxor's Code Snippets</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Thu, 21 Aug 2008 00:50:49 GMT</pubDate>
    <description>DZone Snippets: Vexfluxor's Code Snippets</description>
    <item>
      <title>Displaying the last 10 pages visited from a session</title>
      <link>http://snippets.dzone.com/posts/show/537</link>
      <description>I wanted to store and display an array of the last 10 visited pages in a session. With the help of some folks in #rubyonrails (particularly aqua) this is what i've come up with:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;br /&gt;class ApplicationController &lt; ActionController::Base&lt;br /&gt;	before_filter :add_to_history&lt;br /&gt;	before_filter :page_title&lt;br /&gt;	&lt;br /&gt;	def add_to_history&lt;br /&gt;	  session[:history] ||= []&lt;br /&gt;	  session[:history].unshift ({"url" =&gt; @request.request_uri, "name" =&gt; page_title })&lt;br /&gt;	  session[:history].pop while session[:history].length &gt; 11&lt;br /&gt;	end&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# This bit came from Peter Cooper's snippets source and was moved into the application controller:&lt;br /&gt;&lt;br /&gt;	def page_title&lt;br /&gt;		case self.controller_name&lt;br /&gt;			when 'tag' &lt;br /&gt;				title = "Tags &amp;raquo; " + @params[:tags].join(" &amp;gt; ")&lt;br /&gt;			when 'user'&lt;br /&gt;				title = "Users &amp;raquo; #{@params[:user]}"	 &lt;br /&gt;			when 'features'&lt;br /&gt;					case self.action_name&lt;br /&gt;						when 'show' then title = "Feature &amp;raquo; #{Feature.find(@params[:id]).title}"&lt;br /&gt;						else title = APP_CONFIG["default_title"]&lt;br /&gt;					end&lt;br /&gt;			else &lt;br /&gt;				title = APP_CONFIG["default_title"] + self.controller_name + ":" + self.action_name&lt;br /&gt;		end&lt;br /&gt;	end&lt;br /&gt;	helper_method :page_title&lt;br /&gt;&lt;br /&gt;...&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;In your partial you might do something like this:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;User History&lt;/h4&gt;&lt;br /&gt;&lt;% for cur in session[:history][0..9] -%&gt;&lt;br /&gt;  &lt;p&gt;&lt;a href="&lt;%= cur["url"] %&gt;"&gt;&lt;%= cur["name"] %&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;% end -%&gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Feedback and comments would be appreciated</description>
      <pubDate>Tue, 02 Aug 2005 07:33:37 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/537</guid>
      <author>vexfluxor (michael)</author>
    </item>
  </channel>
</rss>
