title: Including rails datetime helper in custom rake task
body: <p>I want to create a rake task to fill the details of product but the product has to be random in order to format be able to sort it later on based on the date. I would like to include the datehelper provided by the framework in it but I dont seem to have idea on this. How can this be done. My custom rake task looks like this;</p>
  
  <pre><code>namespace :db do
  desc "Filling the data with  products"
    task :fill_products do 
      [{:name =&gt; "1 Galon milk", :price =&gt; 2.99, :released =&gt; Time.now.to_datetime},
      {:name =&gt; "Oh's Cereal'", :price =&gt; 3.95, :released =&gt; 1.year.ago},
      {:name =&gt; "Red T-Shirt", :price =&gt; 12.49, :released =&gt; 2.years.ago},
      {:name =&gt; "Settler's of Catan'", :price =&gt; 29.95, :released =&gt; 2.months.ago},
      {:name =&gt; "Video Game Disc", :price =&gt; 29.95, :released =&gt; 5.moths.ago},
      {:name =&gt; "DVD Player", :price =&gt; 79.99, :released =&gt; 88.days.ago},
      {:name =&gt; "Oak Coffee Table", :price =&gt; 223.99, :released =&gt; 499.days.ago},
      {:name =&gt; "Video Game Console", :price =&gt; 299.95, :released =&gt; 982.days.ago},
      {:name =&gt; "Black Leather Couch", :price =&gt; 399.99, :released =&gt; 1092.days.ago}
      ].each do |attr|
        Product.create!(attr)
      end
    end
  end
  </code></pre>
  
  <p>But as I run the rake command for the task, it gives me error as <code>undefined method 'year' for 1:Fixnum</code>, I suppose this error is due to the fact that it does not have access to the date helper methods provided by rails. So how can I include the helper to enable the support.</p>