<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -30,7 +30,7 @@ It's very simple, and can also be extended to meet more complex demands, such as
   
   # routes as a nested /users/:user_id/articles
   class ArticlesController &lt; ApplicationController
-    fetches :user, :as =&gt; :author, :from =&gt; :user_id, :using =&gt; find_by_login
+    fetches :user, :as =&gt; :author, :from =&gt; :user_id, :using =&gt; :find_by_login
     fetches :article
     
     def index
@@ -44,6 +44,13 @@ a more complex set of requirements:
   class UsersController &lt; ApplicationController
     fetches :user, :from =&gt; Proc.new{ |c| c.params[:user_id] || c.params[:id] }
   end
+  
+Finally, you can use the :initialize option to initialize a new record using
+parameters or Proc-based information:
+
+  fetches :user, :initialize =&gt; true
+  fetches :user, :initialize =&gt; :author # initialize from params[:author]
+  fetches :user, :initialize =&gt; Proc.new{ |c| {:login =&gt; params[:login], :email =&gt; params[:email]} }
 
 The helper method generated memoizes (initializes once then doesn't make additional
 calls to the database) and is available both in the controller and the view.</diff>
      <filename>README</filename>
    </modified>
    <modified>
      <diff>@@ -3,12 +3,17 @@ module ActionController
     def self.included(base) # :nodoc:
       base.class_eval do
         @@default_fetcher_options = { :using =&gt; &quot;find&quot;,
-                                      :from =&gt; :id }
+                                      :from =&gt; :id,
+                                      :initialize =&gt; false }
         cattr_accessor :default_fetcher_options
         
         def self.fetchers # :nodoc:
           read_inheritable_attribute(:fetchers) || write_inheritable_attribute(:fetchers, {})
         end
+        
+        def self.initializing_fetchers # :nodoc:
+          read_inheritable_attribute(:initializing_fetchers) || write_inheritable_attribute(:initializing_fetchers, {})
+        end
 
         # Automatically creates a helper method to fetch a memoized record based on
         # a passed-in parameter.
@@ -22,7 +27,7 @@ module ActionController
         #   # Advanced example with nested route such as /users/:user_id/articles
         #   class ArticlesController &lt; ApplicationController
         #     fetches :user, :as =&gt; :author, :from =&gt; :user_id, :using =&gt; :find_by_login
-        #     fetches :article
+        #     fetches :article, :initialize =&gt; true
         #   end
         #
         #   # Example with Proc-based 'from'
@@ -35,6 +40,7 @@ module ActionController
         # - +as+: the name of the helper method to generate (default is the model name)
         # - +from+: the parameter passed into the finder method (default is +:id+). May also be passed as a Proc that evaluates against a controller argument.
         # - +using+: the class method name to use as a finder (default is +&quot;find&quot;+)
+        # - +initialize+: optionally initialize a new record using parameters if one isn't found. If set to true, initializes from +params[:model_name]+, if false, won't initialize. May also be set to a parameter key or Proc. Default is +false+.
         #
         # Default options may be specified by setting them in an initializer. Example:
         #
@@ -43,8 +49,11 @@ module ActionController
           method_name = options.delete(:as) || default_fetcher_options[:as] || model_name.to_s
           finder = options.delete(:using) || default_fetcher_options[:using]
           from = options.delete(:from) || default_fetcher_options[:from]
+          initializing = options.delete(:initialize) || default_fetcher_options[:initialize]
+          initializing = model_name if initializing == true
           klass = self.respond_to?(:class_eval) ? self : self.metaclass
           fetchers[method_name.to_sym] = from
+          initializing_fetchers[method_name.to_sym] = initializing
           
           klass.class_eval &lt;&lt;-EOS, __FILE__, __LINE__
             def #{method_name}
@@ -53,7 +62,9 @@ module ActionController
               else
                 fetcher = self.class.fetchers[:#{method_name}]
                 from = fetcher.is_a?(Proc) ? fetcher.call(self) : params[fetcher]
-                @#{method_name} = #{model_name.to_s.classify}.#{finder.to_s}(from)
+                initializer = self.class.initializing_fetchers[:#{method_name}]
+                @#{method_name} = #{model_name.to_s.classify}.#{finder.to_s}(from) if from
+                @#{method_name} ||= #{model_name.to_s.classify}.new(initializer.is_a?(Proc) ? initializer.call(self) : params[initializer])  
               end
             end
           EOS</diff>
      <filename>lib/action_controller/fetches.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>de9bbd5a39b0ae5851042560819b5ef3631f60be</id>
    </parent>
  </parents>
  <author>
    <name>Michael Bleigh</name>
    <email>michael@intridea.com</email>
  </author>
  <url>http://github.com/mbleigh/fetches/commit/fe18ae0f5c13db4b6a3672c1af90efd54b08b4aa</url>
  <id>fe18ae0f5c13db4b6a3672c1af90efd54b08b4aa</id>
  <committed-date>2008-07-29T07:33:38-07:00</committed-date>
  <authored-date>2008-07-29T07:33:38-07:00</authored-date>
  <message>Added :initialize option to allow for new record creation in addition to fetching.</message>
  <tree>da53d3bc8fb8ac38001373ec676430c04b9983d9</tree>
  <committer>
    <name>Michael Bleigh</name>
    <email>michael@intridea.com</email>
  </committer>
</commit>
