<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -16,7 +16,7 @@
 #   before_filter :login_required, :except =&gt; [:index, :show]
 module Authentication
   def self.included(controller)
-    controller.send :helper_method, :current_&lt;%= user_singular_name %&gt;, :logged_in?
+    controller.send :helper_method, :current_&lt;%= user_singular_name %&gt;, :logged_in?, :redirect_to_target_or_default
     controller.filter_parameter_logging :password
   end
   
@@ -31,7 +31,19 @@ module Authentication
   def login_required
     unless logged_in?
       flash[:error] = &quot;You must first log in or sign up before accessing this page.&quot;
+      store_target_location
       redirect_to login_url
     end
   end
+  
+  def redirect_to_target_or_default(default)
+    redirect_to(session[:return_to] || default)
+    session[:return_to] = nil
+  end
+  
+  private
+  
+  def store_target_location
+    session[:return_to] = request.request_uri
+  end
 end</diff>
      <filename>rails_generators/nifty_authentication/templates/authentication.rb</filename>
    </modified>
    <modified>
      <diff>@@ -7,7 +7,7 @@ class &lt;%= sessions_class_name %&gt;Controller &lt; ApplicationController
     if &lt;%= user_singular_name %&gt;
       session[:&lt;%= user_singular_name %&gt;_id] = &lt;%= user_singular_name %&gt;.id
       flash[:notice] = &quot;Logged in successfully.&quot;
-      redirect_to root_url
+      redirect_to_target_or_default(root_url)
     else
       flash.now[:error] = &quot;Invalid login or password.&quot;
       render :action =&gt; 'new'</diff>
      <filename>rails_generators/nifty_authentication/templates/sessions_controller.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>eae76670695f8dc1077933690da2b97ad6325b27</id>
    </parent>
  </parents>
  <author>
    <name>James Miller</name>
    <email>james@jkmillertech.com</email>
  </author>
  <url>http://github.com/ryanb/nifty-generators/commit/c82a961915907dce51d985ebd3d0a493c72fbd82</url>
  <id>c82a961915907dce51d985ebd3d0a493c72fbd82</id>
  <committed-date>2009-05-14T12:35:13-07:00</committed-date>
  <authored-date>2009-05-13T16:20:57-07:00</authored-date>
  <message>Store request target location when login is required

Signed-off-by: Ryan Bates &lt;ryan@railscasts.com&gt;</message>
  <tree>53b3430cfc980da319891c4c5f782c71deab5231</tree>
  <committer>
    <name>Ryan Bates</name>
    <email>ryan@railscasts.com</email>
  </committer>
</commit>
