<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -11,12 +11,3 @@ Rake::TestTask.new(:test) do |t|
   t.pattern = 'test/**/*_test.rb'
   t.verbose = true
 end
-
-desc 'Generate documentation for the resouce_this plugin.'
-Rake::RDocTask.new(:rdoc) do |rdoc|
-  rdoc.rdoc_dir = 'rdoc'
-  rdoc.title    = 'resouce_this'
-  rdoc.options &lt;&lt; '--line-numbers' &lt;&lt; '--inline-source'
-  rdoc.rdoc_files.include('README')
-  rdoc.rdoc_files.include('lib/**/*.rb')
-end</diff>
      <filename>Rakefile</filename>
    </modified>
    <modified>
      <diff>@@ -13,42 +13,73 @@ module ResourceThis # :nodoc:
       plural_name           = singular_name.pluralize
       will_paginate_index   = options[:will_paginate] || false
       
+      module_eval &lt;&lt;-&quot;end_eval&quot;, __FILE__, __LINE__
+      before_filter :load_#{singular_name}, :only =&gt; [ :create, :update, :destroy ]
+      before_filter :load_#{plural_name}, :only =&gt; [ :index ]
+      before_filter :new_#{singular_name}, :only =&gt; [ :new ]
+      before_filter :create_#{singular_name}, :only =&gt; [ :create ]
+      before_filter :update_#{singular_name}, :only =&gt; [ :update ]
+      before_filter :destroy_#{singular_name}, :only =&gt; [ :destoy ]
+      
+      protected
+        def load_#{singular_name}
+          @#{singular_name} = #{class_name}.find(params[:id])
+        end
+        
+        def new_#{singular_name}
+          @#{singular_name} = #{class_name}.new
+        end
+        
+        def create_#{singular_name}
+          @#{singular_name} = #{class_name}.new(params[:#{singular_name}])
+          @#{singular_name} = @#{singular_name}.save
+        end
+        
+        def update_#{singular_name}
+          @#{singular_name} = #{class_name}.update_attributes(params[:#{singular_name}])
+        end
+        
+        def destroy_#{singular_name}
+          @#{singular_name} = @#{singular_name}.destroy
+        end
+      end_eval
+      
+      
       if will_paginate_index
         module_eval &lt;&lt;-&quot;end_eval&quot;, __FILE__, __LINE__
-          def index
+          def load_#{plural_name}
             @#{plural_name} = #{class_name}.paginate(:page =&gt; params[:page])
             #TODO: add sorting customizable by subclassed controllers
-            respond_to do |format|
-              format.html
-              format.xml  { render :xml =&gt; @#{plural_name} }
-            end
           end
         end_eval
       else
         module_eval &lt;&lt;-&quot;end_eval&quot;, __FILE__, __LINE__
-          def index
+          def load_#{plural_name}
             @#{plural_name} = #{class_name}.find(:all)
             #TODO: add sorting customizable by subclassed controllers
-            respond_to do |format|
-              format.html
-              format.xml  { render :xml =&gt; @#{plural_name} }
-            end
           end
         end_eval
       end
 
       module_eval &lt;&lt;-&quot;end_eval&quot;, __FILE__, __LINE__
+      public
+        def index
+          @#{plural_name} = #{class_name}.paginate(:page =&gt; params[:page])
+          #TODO: add sorting customizable by subclassed controllers
+          respond_to do |format|
+            format.html
+            format.xml  { render :xml =&gt; @#{plural_name} }
+          end
+        end
 
-        def show
-          @#{singular_name} = #{class_name}.find(params[:id])
+        def show          
           respond_to do |format|
             format.html
             format.xml  { render :xml =&gt; @#{singular_name} }
           end
         end
 
-        def new
-          @#{singular_name} = #{class_name}.new
+        def new          
           respond_to do |format|
             format.html { render :action =&gt; :edit }
             format.xml  { render :xml =&gt; @#{singular_name} }
@@ -56,49 +87,40 @@ module ResourceThis # :nodoc:
         end
 
         def create
-          @#{singular_name} = #{class_name}.create!(params[:#{singular_name}])
-          flash[:notice] = &quot;#{class_name} was successfully created.&quot;
           respond_to do |format|
-            format.html { redirect_to :action =&gt; :index }
-            format.xml  { render :xml =&gt; @#{singular_name}, :status =&gt; :created, :location =&gt; @#{singular_name} }
-          end
-        rescue ActiveRecord::RecordInvalid
-          flash[:error] = @#{singular_name}.errors
-          respond_to do |format|
-            format.html { render :action =&gt; :new }
-            format.xml  { render :xml =&gt; @#{singular_name}.errors, :status =&gt; :unprocessable_entity }
+            if @#{singular_name}
+              flash[:notice] = '#{class_name} was successfully created.'
+              format.html { redirect_to @#{singular_name} }
+              format.xml  { render :xml =&gt; @#{singular_name}, :status =&gt; :created, :location =&gt; @#{singular_name} }
+            else
+              format.html { render :action =&gt; :new }
+              format.xml  { render :xml =&gt; @#{singular_name}.errors, :status =&gt; :unprocessable_entity }
+            end
           end
         end 
 
         def edit
-          @#{singular_name} = #{class_name}.find(params[:id])
         end
 
         def update
-          @#{singular_name} = #{class_name}.find(params[:id])
-          @#{singular_name}.update_attributes!(params[:#{singular_name}])
-          flash[:notice] = &quot;#{class_name} was successfully updated.&quot;
           respond_to do |format|
-            format.html { redirect_to @#{singular_name} }
-            format.xml  { head :ok }
-          end
-        rescue ActiveRecord::RecordInvalid
-          flash[:error] = @#{singular_name}.errors
-          respond_to do |format|
-            format.html { render :action =&gt; :edit }
-            format.xml  { render :xml =&gt; @#{singular_name}.errors, :status =&gt; :unprocessable_entity }
+            if @#{singular_name}
+              flash[:notice] = '#{class_name} was successfully updated.'
+              format.html { redirect_to @#{singular_name} }
+              format.xml  { head :ok }
+            else
+              format.html { render :action =&gt; :edit }
+              format.xml  { render :xml =&gt; @#{singular_name.errors, :status =&gt; :unprocessable_entity }
+            end
           end
         end
 
-        def destroy
-          @#{singular_name} = #{class_name}.find(params[:id])
-          @#{singular_name} = @#{singular_name}.destroy
+        def destroy          
           respond_to do |format|
-            format.html { redirect_to :action =&gt; :index }
+            format.html { redirect_to :action =&gt; #{plural_name}_url }
             format.xml  { head :ok }
           end
         end
-
       end_eval
     end
   end</diff>
      <filename>lib/resource_this.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>eaaaf7499745419dace8337c642a147efc74622e</id>
    </parent>
  </parents>
  <author>
    <name>jnewland</name>
    <email>jnewland@9b6b69f6-dd27-0410-8144-a0f3c56a22ea</email>
  </author>
  <url>http://github.com/jnewland/resource_this/commit/6668104fd3780a0aa8686b9bce2224bd8d10cf88</url>
  <id>6668104fd3780a0aa8686b9bce2224bd8d10cf88</id>
  <committed-date>2007-09-16T12:03:44-07:00</committed-date>
  <authored-date>2007-09-16T12:03:44-07:00</authored-date>
  <message>refactor to use before_filters

git-svn-id: http://jnewland.com/svn/public/ruby/rails/plugins/resource_this@21 9b6b69f6-dd27-0410-8144-a0f3c56a22ea</message>
  <tree>a82564a08017f058372af104f4e6604438bd97f7</tree>
  <committer>
    <name>jnewland</name>
    <email>jnewland@9b6b69f6-dd27-0410-8144-a0f3c56a22ea</email>
  </committer>
</commit>
