<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>26Blog &#187; Rails</title>
	<atom:link href="http://2007.26webs.com/blog/category/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://2007.26webs.com/blog</link>
	<description></description>
	<lastBuildDate>Fri, 13 Feb 2009 04:58:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9-rare</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>A Rake Task for Faker</title>
		<link>http://2007.26webs.com/blog/2008/02/02/a-rake-task-for-faker/</link>
		<comments>http://2007.26webs.com/blog/2008/02/02/a-rake-task-for-faker/#comments</comments>
		<pubDate>Sun, 03 Feb 2008 03:16:59 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[faker]]></category>
		<category><![CDATA[rake task]]></category>
		<category><![CDATA[rubyonrails]]></category>

		<guid isPermaLink="false">http://26webs.com/blog/2008/02/02/a-rake-task-for-faker/</guid>
		<description><![CDATA[Need to insert some fake data in your development database? Grab the Faker gem and drop this into lib/tasks/fake_data.rb. Customize it for your model(s) and execute with rake db:development:fake_data.

namespace :db do
  namespace :development do
    desc &#34;Create records in the development database.&#34;
    task :fake_data =&#62; :environment do
   [...]]]></description>
			<content:encoded><![CDATA[<p>Need to insert some fake data in your development database? Grab the Faker gem and drop this into <code>lib/tasks/fake_data.rb</code>. Customize it for your model(s) and execute with <code>rake db:development:fake_data</code>.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">namespace <span style="color:#ff3333; font-weight:bold;">:db</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  namespace <span style="color:#ff3333; font-weight:bold;">:development</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    desc <span style="color:#996600;">&quot;Create records in the development database.&quot;</span>
    task <span style="color:#ff3333; font-weight:bold;">:fake_data</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:environment</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'faker'</span>
&nbsp;
      100.<span style="color:#9900CC;">times</span> <span style="color:#9966CC; font-weight:bold;">do</span>
        c = Client.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span>
          <span style="color:#ff3333; font-weight:bold;">:first_name</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#6666ff; font-weight:bold;">Faker::Name</span>.<span style="color:#9900CC;">first_name</span>,
          <span style="color:#ff3333; font-weight:bold;">:last_name</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#6666ff; font-weight:bold;">Faker::Name</span>.<span style="color:#9900CC;">last_name</span>,
          <span style="color:#ff3333; font-weight:bold;">:middle_initial</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;A&quot;</span>..<span style="color:#996600;">&quot;Z&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">to_a</span>.<span style="color:#CC0066; font-weight:bold;">rand</span>, 
          <span style="color:#ff3333; font-weight:bold;">:ss_number</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">99999999</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#CC0066; font-weight:bold;">rand</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">999999999</span> <span style="color:#006600; font-weight:bold;">-</span> <span style="color:#006666;">99999999</span><span style="color:#006600; font-weight:bold;">&#41;</span>, 
          <span style="color:#ff3333; font-weight:bold;">:date_of_birth</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span> <span style="color:#006600; font-weight:bold;">-</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0066; font-weight:bold;">rand</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">12000</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">days</span><span style="color:#006600; font-weight:bold;">&#41;</span> 
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>I&#8217;m sure there&#8217;s more optimization to be done, but it works for me!</p>
<p>UPDATE: I added a few extra lines for data outside of faker.</p>
]]></content:encoded>
			<wfw:commentRss>http://2007.26webs.com/blog/2008/02/02/a-rake-task-for-faker/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
