<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -12,28 +12,26 @@ module ResourceThis # :nodoc:
       class_name            = options[:class_name] || singular_name.camelize
       plural_name           = singular_name.pluralize
       will_paginate_index   = options[:will_paginate] || false
-      url_string            = &quot;#{singular_name}_url(@#{singular_name})&quot;
-      list_url_string       = &quot;#{plural_name}_url&quot;
-      finder_base           = class_name
+      resource_url          = &quot;#{singular_name}_url(@#{singular_name})&quot;
+      collection_url        = &quot;#{plural_name}_url&quot;
+      resource_url          = options[:path_prefix] + resource_url unless options[:path_prefix].nil?
+      collection_url        = options[:path_prefix] + collection_url unless options[:path_prefix].nil?
       
       class_inheritable_accessor :resource_this_finder_options
       self.resource_this_finder_options = options[:finder_options] || {}
       
       unless options[:nested].nil?
-        nested              = options[:nested].to_s.singularize
-        nested_class        = nested.camelize
-        url_string          = &quot;#{nested}_#{singular_name}_url(&quot; + [nested, singular_name].map { |route| &quot;@#{route}&quot;}.join(', ') + ')'
-        list_url_string     = &quot;#{nested}_#{plural_name}_url(@#{nested})&quot;
-        finder_base         = &quot;@#{nested}.#{plural_name}&quot;
+        nested                = options[:nested].to_s.singularize
+        nested_class          = nested.camelize
+        nested_resource_url   = &quot;#{nested}_#{singular_name}_url(&quot; + [nested, singular_name].map { |route| &quot;@#{route}&quot;}.join(', ') + ')'
+        nested_collection_url = &quot;#{nested}_#{plural_name}_url(@#{nested})&quot;
+        nested_resource_url   = options[:path_prefix] + nested_resource_url unless options[:path_prefix].nil?
+        nested_collection_url = options[:path_prefix] + nested_collection_url unless options[:path_prefix].nil?
         module_eval &lt;&lt;-&quot;end_eval&quot;, __FILE__, __LINE__
           before_filter :load_#{nested}
         end_eval
       end
-      
-      #process path_prefix
-      url_string            = options[:path_prefix] + url_string unless options[:path_prefix].nil?
-      list_url_string       = options[:path_prefix] + list_url_string unless options[:path_prefix].nil?
-      
+
       #standard before_filters
       module_eval &lt;&lt;-&quot;end_eval&quot;, __FILE__, __LINE__
         before_filter :load_#{singular_name}, :only =&gt; [ :show, :edit, :update, :destroy ]
@@ -42,29 +40,69 @@ module ResourceThis # :nodoc:
         before_filter :create_#{singular_name}, :only =&gt; [ :create ]
         before_filter :update_#{singular_name}, :only =&gt; [ :update ]
         before_filter :destroy_#{singular_name}, :only =&gt; [ :destroy ]
+      
       protected
+      
+        def finder_options
+          resource_this_finder_options.class == Proc ? resource_this_finder_options.call : {}
+        end
+      
       end_eval
       
-      unless options[:nested].nil?
+      if options[:nested].nil?
+        module_eval &lt;&lt;-&quot;end_eval&quot;, __FILE__, __LINE__
+          def finder_base
+            #{class_name}
+          end
+          
+          def collection
+            #{class_name}.find(:all, finder_options)
+          end
+          
+          def collection_url
+            #{collection_url}
+          end
+
+          def resource_url
+            #{resource_url}
+          end
+        end_eval
+      else
         module_eval &lt;&lt;-&quot;end_eval&quot;, __FILE__, __LINE__
           def load_#{nested}
-            @#{nested} = #{nested_class}.find(params[:#{nested}_id])
+            @#{nested} = #{nested_class}.find(params[:#{nested}_id]) rescue nil
+          end
+          
+          def finder_base
+            @#{nested}.nil? ? #{class_name} : @#{nested}.#{plural_name}
+          end
+          
+          def collection
+            @#{nested}.nil? ? #{class_name}.find(:all, finder_options) : @#{nested}.#{plural_name}.find(:all, finder_options)
+          end
+          
+          def collection_url
+            @#{nested}.nil? ? #{collection_url} : #{nested_collection_url}
+          end
+
+          def resource_url
+            @#{nested}.nil? ? #{resource_url} : #{nested_resource_url}
           end
         end_eval
       end
       
       module_eval &lt;&lt;-&quot;end_eval&quot;, __FILE__, __LINE__
         def load_#{singular_name}
-          @#{singular_name} = #{finder_base}.find(params[:id])
+          @#{singular_name} = finder_base.find(params[:id])
         end
         
         def new_#{singular_name}
-          @#{singular_name} = #{finder_base}.new
+          @#{singular_name} = finder_base.new
         end
         
         def create_#{singular_name}
           returning true do
-            @#{singular_name} = #{finder_base}.new(params[:#{singular_name}])
+            @#{singular_name} = finder_base.new(params[:#{singular_name}])
             @created = @#{singular_name}.save
           end
         end
@@ -80,19 +118,16 @@ module ResourceThis # :nodoc:
         end
       end_eval
             
-      #TODO: add sorting customizable by subclassed controllers      
       if will_paginate_index
         module_eval &lt;&lt;-&quot;end_eval&quot;, __FILE__, __LINE__
           def load_#{plural_name}
-            finder_options = resource_this_finder_options.class == Proc ? resource_this_finder_options.call : resource_this_finder_options
-            @#{plural_name} = #{finder_base}.paginate(finder_options.merge(:page =&gt; params[:page]))
+            @#{plural_name} = finder_base.paginate(finder_options.merge(:page =&gt; params[:page]))
           end
         end_eval
       else
         module_eval &lt;&lt;-&quot;end_eval&quot;, __FILE__, __LINE__
           def load_#{plural_name}
-            finder_options = resource_this_finder_options.class == Proc ? resource_this_finder_options.call : resource_this_finder_options
-            @#{plural_name} = #{finder_base}.find(:all, finder_options)
+            @#{plural_name} = collection
           end
         end_eval
       end
@@ -127,8 +162,8 @@ module ResourceThis # :nodoc:
           respond_to do |format|
             if @created
               flash[:notice] = '#{class_name} was successfully created.'
-              format.html { redirect_to #{url_string} }
-              format.xml  { render :xml =&gt; @#{singular_name}, :status =&gt; :created, :location =&gt; #{url_string} }
+              format.html { redirect_to(resource_url) }
+              format.xml  { render :xml =&gt; @#{singular_name}, :status =&gt; :created, :location =&gt; resource_url }
               format.js
             else
               format.html { render :action =&gt; :edit }
@@ -149,7 +184,7 @@ module ResourceThis # :nodoc:
           respond_to do |format|
             if @updated
               flash[:notice] = '#{class_name} was successfully updated.'
-              format.html { redirect_to #{url_string} }
+              format.html { redirect_to(resource_url) }
               format.xml  { head :ok }
               format.js
             else
@@ -162,7 +197,7 @@ module ResourceThis # :nodoc:
 
         def destroy          
           respond_to do |format|
-            format.html { redirect_to #{list_url_string} }
+            format.html { redirect_to(collection_url) }
             format.xml  { head :ok }
             format.js
           end</diff>
      <filename>lib/resource_this.rb</filename>
    </modified>
    <modified>
      <diff>@@ -7,11 +7,14 @@ class ResourceThisNestingTest &lt; Test::Unit::TestCase
     @request.accept = 'application/xml'  
     @response   = ActionController::TestResponse.new
     @first = Post.create(:title =&gt; &quot;test&quot;, :body =&gt; &quot;test&quot;)
+    @second = Post.create(:title =&gt; &quot;test2&quot;, :body =&gt; &quot;test2&quot;)
     @first_comment = Comment.create(:post =&gt; @first, :body =&gt; &quot;test&quot;)
+    @second_comment = Comment.create(:post =&gt; @second, :body =&gt; &quot;test&quot;)
     ActionController::Routing::Routes.draw do |map|  
       map.resources :posts do |post|
         post.resources :comments
       end
+      map.resources :comments
     end
   end
   
@@ -23,8 +26,15 @@ class ResourceThisNestingTest &lt; Test::Unit::TestCase
   def test_should_get_index
     get :index, :post_id =&gt; @first.id
     assert_response :success
-    assert assigns(:comments)
-    assert assigns(:post)
+    assert_equal @first.comments, assigns(:comments)
+    assert_equal @first, assigns(:post)
+  end
+
+  def test_should_get_index_without_post
+    get :index
+    assert_response :success
+    assert assigns(:post).nil?
+    assert_equal Comment.find(:all), assigns(:comments)
   end
 
   def test_should_get_new
@@ -34,9 +44,16 @@ class ResourceThisNestingTest &lt; Test::Unit::TestCase
     assert assigns(:post)
   end
 
+  def test_should_get_new_without_post
+    get :new
+    assert_response :success
+    assert assigns(:post).nil?
+    assert assigns(:comment)
+  end
+
   def test_should_create_comment
     assert_difference('Comment.count') do
-      post :create, :post_id =&gt; @first.id, :post =&gt; { :body =&gt; &quot;test&quot; }
+      post :create, :post_id =&gt; @first.id, :comment =&gt; { :body =&gt; &quot;test&quot; }
     end
     assert_response :created
     assert assigns(:comment)
@@ -46,11 +63,19 @@ class ResourceThisNestingTest &lt; Test::Unit::TestCase
   def test_should_create_comment_html
     @request.accept = 'text/html'
     assert_difference('Comment.count') do
-      post :create, :post_id =&gt; @first.id, :post =&gt; { :body =&gt; &quot;test&quot; }
+      post :create, :post_id =&gt; @first.id, :comment =&gt; { :body =&gt; &quot;test&quot; }
     end
     assert_redirected_to &quot;posts/#{assigns(:post).id}/comments/#{assigns(:comment).id}&quot;
   end
 
+  def test_should_create_comment_html_without_post
+    @request.accept = 'text/html'
+    assert_difference('Comment.count') do
+      post :create, :comment =&gt; { :body =&gt; &quot;test&quot; }
+    end
+    assert_redirected_to &quot;/comments/#{assigns(:comment).id}&quot;
+  end
+
   def test_should_show_comment
     get :show, :post_id =&gt; @first.id, :id =&gt; @first_comment.id
     assert_response :success
@@ -58,6 +83,13 @@ class ResourceThisNestingTest &lt; Test::Unit::TestCase
     assert assigns(:post)
   end
 
+  def test_should_show_comment_without_post
+    get :show, :id =&gt; @first_comment.id
+    assert_response :success
+    assert_equal Comment.find(@first_comment.id), assigns(:comment)
+    assert assigns(:post).nil?
+  end
+
   def test_should_update_comment
     put :update, :post_id =&gt; @first.id, :id =&gt; @first_comment.id, :comment =&gt; { :post =&gt; @first, :body =&gt; &quot;test&quot; }
     assert_response :success
@@ -71,6 +103,12 @@ class ResourceThisNestingTest &lt; Test::Unit::TestCase
     assert_redirected_to &quot;posts/#{assigns(:post).id}/comments/#{assigns(:comment).id}&quot;
   end
 
+  def test_should_update_comment_html_without_post
+    @request.accept = 'text/html'
+    put :update, :id =&gt; @first_comment.id, :comment =&gt; { :post =&gt; @first, :body =&gt; &quot;test2&quot; }
+    assert_redirected_to &quot;/comments/#{assigns(:comment).id}&quot;
+  end
+
   def test_should_destroy_comment
     assert_difference('Comment.count', -1) do
       delete :destroy, :post_id =&gt; @first.id, :id =&gt; @first_comment.id
@@ -85,4 +123,12 @@ class ResourceThisNestingTest &lt; Test::Unit::TestCase
     end
     assert_redirected_to &quot;posts/#{assigns(:post).id}/comments&quot;
   end
+
+  def test_should_destroy_html_without_post
+    @request.accept = 'text/html'
+    assert_difference('Comment.count', -1) do
+      delete :destroy, :id =&gt; @first_comment.id
+    end
+    assert_redirected_to &quot;/comments&quot;
+  end
 end</diff>
      <filename>test/resource_this_netsting_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -27,8 +27,8 @@ class ResourceThisSortingTest &lt; Test::Unit::TestCase
     assert_equal @a, assigns(:widgets).first
   end
   
-  def test_should_get_index_sorted
-    @controller.resource_this_finder_options = {:order =&gt; 'body'}
+  def test_should_get_index_sorted_with_inline_proc
+    @controller.resource_this_finder_options = Proc.new { { :order =&gt; 'body' } }
     get :index
     assert_response :success
     assert assigns(:widgets)</diff>
      <filename>test/resource_this_sorting_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -15,7 +15,8 @@ end
 RAILS_ROOT = '.'    unless defined? RAILS_ROOT
 RAILS_ENV  = 'test' unless defined? RAILS_ENV
 
-
+ActiveRecord::Base.logger = Logger.new(STDOUT) if ENV['DEBUG']
+ActionController::Base.logger = Logger.new(STDOUT) if ENV['DEBUG']
 
 ActionController::Base.send :include, ResourceThis
 </diff>
      <filename>test/test_helper.rb</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>TODO</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>0f80f8e919d74f95fa4e64759491b5654eed5ebe</id>
    </parent>
  </parents>
  <author>
    <name>Jesse Newland</name>
    <email>jnewland@gmail.com</email>
  </author>
  <url>http://github.com/jnewland/resource_this/commit/5f3af150a298bb3fe0bb99f1709b139f3fd81a8d</url>
  <id>5f3af150a298bb3fe0bb99f1709b139f3fd81a8d</id>
  <committed-date>2008-03-03T13:51:18-08:00</committed-date>
  <authored-date>2008-03-03T13:51:18-08:00</authored-date>
  <message>lots of work to improve nested resource support</message>
  <tree>76cbe431b86efa0a3860d5c8f812dfd608f88dda</tree>
  <committer>
    <name>Jesse Newland</name>
    <email>jnewland@gmail.com</email>
  </committer>
</commit>
