<?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>databasically // Kansas City Small Business IT &#38;&#38; Ruby on Rails Programming &#187; Ruby on Rails</title>
	<atom:link href="http://databasically.com/category/blog/programming/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://databasically.com</link>
	<description>Kansas City Small Business IT</description>
	<lastBuildDate>Fri, 03 Feb 2012 05:24:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Configuration for mailjet email delivery with Ruby on Rails</title>
		<link>http://databasically.com/2011/06/07/configuration-for-mailjet-email-delivery-with-ruby-on-rails/</link>
		<comments>http://databasically.com/2011/06/07/configuration-for-mailjet-email-delivery-with-ruby-on-rails/#comments</comments>
		<pubDate>Tue, 07 Jun 2011 10:00:03 +0000</pubDate>
		<dc:creator>Wes</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://databasically.com/?p=583</guid>
		<description><![CDATA[Setting up mailjet.com to deliver your mail via Ruby on Rails? Here&#8217;s how, because their Getting Started is nothing but placeholder headers right now. Create an account Go to https://www.mailjet.com and create an account. Note: the word &#8220;Faculatative&#8221; means &#8220;optional&#8221; on the signup form. Add your sending address Add a sending address (Accounts > Sender [...]]]></description>
			<content:encoded><![CDATA[<p>Setting up mailjet.com to deliver your mail via Ruby on Rails?  Here&#8217;s how, because their <a href="https://www.mailjet.com/docs/getting_started">Getting Started</a> is nothing but placeholder headers right now.</p>
<div class="thumbnail"><a href="https://skitch.com/wesg/fdkc8/mailjet-real-time-emailing-mailjet.com"><img src="https://img.skitch.com/20110607-bmbfb3f4pjrcawsya4yab9dcic.preview.jpg" alt="Mailjet : Real-time Emailing - mailjet.com" /></a></div>
</p>
<p><span id="more-583"></span><br />
<h2>Create an account</h2>
<p>Go to <a href="https://www.mailjet.com">https://www.mailjet.com</a> and create an account.</p>
<p>Note: the word &#8220;Faculatative&#8221; means &#8220;optional&#8221; on the signup form.</p>
<h2>Add your sending address</h2>
<ul>
<li>Add a sending address (Accounts > <a href="https://www.mailjet.com/account/sender">Sender Addresses</a>)</li>
<li>Update your Rails ActionMailer configuration
<ul>
<li>Find the settings you need at: <a href="https://www.mailjet.com/account/setup">https://www.mailjet.com/account/setup</a></p>
<pre>
    SMTP server:
    in.mailjet.com

    Username (API Key):
    12345678901234567890

    Password (Secret Key):
    99999999999999999999999999999999

    Port:
    25 or 587 (some providers block port 25)

    Use TLS:
    yes
  </pre>
</li>
<li>Set these settings in config/application.rb (or config/environments/production.rb):
<pre name="code" class="ruby">

    config.action_mailer.raise_delivery_errors = false
    config.action_mailer.perform_deliveries = true

    config.action_mailer.smtp_settings = {
      :address => "in.mailjet.com",
      :enable_starttls_auto => true,
      :port => 587,
      :authentication => 'plain',
      :user_name => "12345678901234567890",
      :password => "99999999999999999999999999999999"
    }
</pre>
</li>
</ul>
</li>
</ul>
<h2>Setup domain authentication (SPF and/or DomainKeys/DKIM)</h2>
<h3>SPF</h3>
<p>
  <img src="https://img.skitch.com/20110607-nmn91j4ukdp8yna3pup3qu1sb8.png" alt="My Account - mailjet.com" /><br />
  Click <b>Domain DNS and SMTP setup</b>.<br />
  Then, under <b>Domain Authentication</b>, click your domain.
</p>
<p>Setting up SPF requires adding a DNS entry. Mailjet will look at your existing one and give you the one to replace it with.<br />
  It&#8217;ll look something like: <br /><code>domainname.com.	IN TXT "v=spf1 include:spf.mailjet.com mx ~all"</code><br />
  In my DNS manager, I created a TXT record, gave it a name of &#8220;domainname.com.&#8221; and set the value to the <br /><code>'v=spf1 include:spf.mailjet.com mx ~all'</code> portion (without the quotes).  The full example they give you is for the DNS zone syntax, which you may or may not have.</p>
<p>  If you need help configuring this, <a href="/contact-us">we would be happy to help you</a>.</p>
<h3>DKIM</h3>
<p>
  This is similar, a TXT record that has a key that identifies your server so mail can be sent.  Same deal.
</p>
<h2>Test</h2>
<p>Deploy your changes and kick off something that sends a mailer.  We have a Notifier model that has a <code>test_email()</code> method that I just called from the console to push a test through.  I just went to the reports and saw it there.</p>
<p>All in all, the service seems a little rough around the edges, mostly due to it being a French company that could use a little work on the translations and some serious love on the support documentations.  Hope this helps you get started with Mailjet configuration!</p>
]]></content:encoded>
			<wfw:commentRss>http://databasically.com/2011/06/07/configuration-for-mailjet-email-delivery-with-ruby-on-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gateway timeout with nginx/passenger standalone</title>
		<link>http://databasically.com/2011/04/18/gateway-timeout-with-nginxpassenger-standalone/</link>
		<comments>http://databasically.com/2011/04/18/gateway-timeout-with-nginxpassenger-standalone/#comments</comments>
		<pubDate>Mon, 18 Apr 2011 15:18:52 +0000</pubDate>
		<dc:creator>Wes</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://databasically.com/?p=528</guid>
		<description><![CDATA[I needed to run Rails apps with both ruby 1.8.7 and 1.9.2 on the same server. Passenger Standalone to the rescue! Setting up my 1.9.2 app as a standalone server and setting it up as proxy to it worked great. Until we had to upload and process some files. Turns out, the gateway server would [...]]]></description>
			<content:encoded><![CDATA[<p>I needed to run Rails apps with both ruby 1.8.7 and 1.9.2 on the same server.</p>
<p><a href="http://www.modrails.com/documentation/Users%20guide%20Standalone.html">Passenger Standalone</a> to the rescue!  Setting up my 1.9.2 app as a standalone server and setting it up as proxy to it worked great.</p>
<p><strong>Until</strong> we had to upload and process some files.  Turns out, the gateway server would timeout, even though the process was still processing on the app server.</p>
<p>The proxing nginx server would reply with &#8220;Gateway Timeout 504&#8243;.</p>
<p>The fix from the nginx documentation: <a href="http://wiki.nginx.org/HttpProxyModule#proxy_read_timeout">proxy_read_timeout</a></p>
<p>My proxy config after this:</p>
<pre name="code" class="ruby">
  location / {
    proxy_pass http://127.0.0.1:3010;
    proxy_read_timeout 240s;
  }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://databasically.com/2011/04/18/gateway-timeout-with-nginxpassenger-standalone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Thebes, profiling spork, backup rubygem</title>
		<link>http://databasically.com/2011/03/14/thebes-profiling-spork-backup-rubygem/</link>
		<comments>http://databasically.com/2011/03/14/thebes-profiling-spork-backup-rubygem/#comments</comments>
		<pubDate>Mon, 14 Mar 2011 15:41:34 +0000</pubDate>
		<dc:creator>Wes</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://databasically.com/?p=506</guid>
		<description><![CDATA[Thebes, a new minimal sphinx gem for Rails Link Thebes is a wrapper around Sphinx, the search engine we use on most of our projects. Thebes differs from other solutions by staying as far away from your Rails code as possible. Instead of hiding the Sphinx configuration file behind a domain-specific language, this library assumes [...]]]></description>
			<content:encoded><![CDATA[<h1 id="thebes_a_new_minimal_sphinx_gem_for_rails">Thebes, a new minimal sphinx gem for Rails</h1>
<p><a href="www.getharvest.com/blog/2011/03/thebes-a-new-minimal-sphinx-gem-for-rails/" title="Thebes">Link</a></p>
<blockquote>
<p>Thebes is a wrapper around Sphinx, the search engine we use on most of our projects. Thebes differs from other solutions by staying as far away from your Rails code as possible. Instead of hiding the Sphinx configuration file behind a domain-specific language, this library assumes you will write Sphinx config files by hand. In Thebes, you edit an ERB template of your Sphinx configuration and populate it with variables at generation time. For developers needing the most flexible or fastest solution possible, this is a great way to work with Sphinx.</p>
</blockquote>
<p>We&#8217;ve been doing some interesting things with search and reporting that are going to require faster lookups than directly querying the database. From the article &#8220;the [Thinking Sphinx project] has a lot of complexity and ties to ActiveRecord 2.x code. Consequently, the porting of TS to Rails 3 isn’t turning out to be the smooth road we hoped for.  So, for Rails 3 projects, this looks like a good way to go if you&#8217;re willing to get your hands dirty and build some sphinx files yourself.</p>
<h1 id="profiling_spork_for_faster_start_up_time">Profiling Spork for faster start-up time</h1>
<p><a href="http://opinionated-programmer.com/2011/02/profiling-spork-for-faster-start-up-time/" title="Profiling Spork">Link</a></p>
<p>Spork allows you to preload Rails environment files into a process, then it forks that process and runs your tests against the new process.  In essence, your tests will start faster because they&#8217;re not loading everything.  You can specify files you want to be reloaded each time (for instance, model files).</p>
<p>The code:</p>
<p><script src="https://gist.github.com/869238.js"> </script></p>
<p>This prints out everything being loaded up, so you can move files that don&#8217;t change into the preload block for that extra bit of snappiness.</p>
<h1 id="backup_a_rubygem_for_database_and_file_backups">Backup, a rubygem for database and file backups</h1>
<p><a href="https://github.com/meskyanichi/backup" title="Backup rubygem">Link</a></p>
<blockquote>
<p>Backup is a RubyGem (for UNIX-like operating systems: Linux, Mac OSX) that allows you to configure and perform backups in a simple manner using an elegant Ruby DSL. It supports various databases (MySQL, PostgreSQL, MongoDB and Redis), it supports various storage locations (Amazon S3, Rackspace Cloud Files, Dropbox, any remote server through FTP, SFTP, SCP and RSync), it can archive files and folders, it can cycle backups, it can do incremental backups, it can compress backups, it can encrypt backups (OpenSSL or GPG), it can notify you about successful and/or failed backups (Mail or Twitter). It is very extensible and easy to add new functionality to. It&#8217;s easy to use.</p>
</blockquote>
<p>Check out the <a href="https://github.com/meskyanichi/backup/blob/develop/README.md" title="README">README</a> for all the details, but this allows you to backup your app via command line, pushing to S3 or rsync&#8217;ing to another server.  You can schedule it with the fantastic <a href="https://github.com/javan/whenever" title="Whenever gem">Whenever gem</a> too.</p>
]]></content:encoded>
			<wfw:commentRss>http://databasically.com/2011/03/14/thebes-profiling-spork-backup-rubygem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A :limit of Rails&#8217; Migrations</title>
		<link>http://databasically.com/2011/03/01/a-limit-of-rails-migrations/</link>
		<comments>http://databasically.com/2011/03/01/a-limit-of-rails-migrations/#comments</comments>
		<pubDate>Tue, 01 Mar 2011 16:35:51 +0000</pubDate>
		<dc:creator>Samuel Mullen</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://databasically.com/?p=472</guid>
		<description><![CDATA[Migrations in Ruby on Rails use the &#8220;:limit&#8221; symbol to set the maximum length of the underlying field&#8217;s data type. Take for example, the following example migration: create_table :things do &#124;t&#124; t.string :name, :limit =&#62; 32 t.string :description t.timestamps end By default, Rails will create :description as data type &#8220;varchar(255)&#8221; and :name as &#8220;varchar(32)&#8221; in [...]]]></description>
			<content:encoded><![CDATA[<p>Migrations in Ruby on Rails use the &#8220;:limit&#8221; symbol to set the maximum length of the underlying field&#8217;s data type. Take for example, the following example migration:</p>
<pre name='code' class="ruby">create_table :things do |t|
  t.string :name, :limit =&gt; 32
  t.string :description
  t.timestamps
end
</pre>
<p>By default, Rails will create :description as data type &#8220;varchar(255)&#8221; and :name as &#8220;varchar(32)&#8221; in a MySQL database. But did you know you can set :limit to be greater than 255?</p>
<p>For whatever reason, many of us have gained the impression that 255 is the longest :string can be, but that just isn&#8217;t the case. If I wanted the :description field in the example above to be greater than 255, I could just define it as follows:</p>
<pre name='code' class="ruby">t.string :description, :limit =&gt; 1024
</pre>
<p>In fact, strings (i.e. varchars) in MySQL can hold up to 65,535 bytes of data.</p>
<p>The opinionated nature of  Ruby on Rails is a great asset in most instances, but we have to be careful not to let its opinions :limit us.</p>
<p><strong>Note:</strong> I&#8217;m pretty sure Rails sets the default limit of strings to be 255 for two reasons: 1) cross database compatability, and 2) MySQL&#8217;s InnoDB (utf-8) engine can&#8217;t index varchar fields exceeding 255 characters.</p>
<h3>Further Reading</h3>
<ul>
<li><a href="http://www.railsinside.com/misc/455-the-perils-of-opinionated-software-like-rails.html">The Perils Of Opinionated Software (like Rails)</a></li>
<li><a href="http://dev.mysql.com/doc/refman/5.0/en/data-types.html">MySQL Data Types</a></li>
<li><a href="http://dev.mysql.com/doc/refman/5.0/en/innodb-restrictions.html">Restrictions on InnoDB Tables</a></li>
<li><a href="http://dev.mysql.com/doc/refman/5.0/en/char.html">The CHAR and VARCHAR Data Types</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://databasically.com/2011/03/01/a-limit-of-rails-migrations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>default_scope: Use Cases, Caveats, and Work Arounds</title>
		<link>http://databasically.com/2011/02/07/default_scope-use-cases-caveats-and-work-arounds/</link>
		<comments>http://databasically.com/2011/02/07/default_scope-use-cases-caveats-and-work-arounds/#comments</comments>
		<pubDate>Mon, 07 Feb 2011 14:57:09 +0000</pubDate>
		<dc:creator>Samuel Mullen</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[ActiveRecord]]></category>
		<category><![CDATA[default_scope]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://databasically.com/?p=432</guid>
		<description><![CDATA[In Ruby on Rails, named scopes are class methods used to restrict and organize the data searched for. In SQL terms, a named scope adds to the conditional (WHERE) and sorting (ORDER) sections of a query. See Railscast #108 for more information. In Rails 2.3.x, a new type of scoping was added to the API: [...]]]></description>
			<content:encoded><![CDATA[<p>In Ruby on Rails, named scopes are class methods used to restrict and organize the data searched for. In SQL terms, a named scope adds to the conditional (WHERE) and sorting (ORDER) sections of a query. See <a href="http://railscasts.com/episodes/108-named-scope">Railscast #108</a> for more information.</p>
<p>In Rails 2.3.x, a new type of scoping was added to the API: the default_scope. By using &#8220;default_scope&#8221;, one could restrict the data retrieved by every query without the need for extra method calls; it would just happen by &#8220;default&#8221;. If you wanted to have your data sorted in a particular manner, you could add &#8220;default_scope, :order =&gt; &#8216;created_at DESC&#8217;&#8221; to your model. From then on, all data retrieved would be ordered by &#8220;created_at&#8221; in a &#8220;descending&#8221; manner.</p>
<h2>Caveats</h2>
<p>In general, default_scope should be avoided if possible. Here are a few reasons:</p>
<ul>
<li>Out of site, out of mind: Because you don&#8217;t see that you are scoping your data as you query it, it&#8217;s easy to forget that it is in actuality being filtered. This can lead to a lot of head scratching until you remember the default_scope.</li>
<li>default_scope is inherited: All subclasses of the original model will inherit the default scoping. This may not be the behavior you desire.</li>
<li>Extra overhead: It&#8217;s one thing if you need your data sorted every single time, it&#8217;s quite another if you don&#8217;t. By using default_scope, you may be unnecessarily burdening your database.</li>
</ul>
<h2>Use Cases</h2>
<p>Like curry, default_scope is not inherently evil (obscure Phineas and Ferb reference), and there are instances where using it makes good sense. As an example, here at Databasically, we use default_scope to limit data retrieved by one application to a subset of what is available in a table. There will never be an instance where all the available data will be required, and so we limit it by default.</p>
<p>Here are the two use cases:</p>
<ul>
<li>When <strong>only</strong> a subset of the data is ever required</li>
<li>When the data must be returned in a specific order <strong>every</strong> time</li>
</ul>
<h2>Work Arounds</h2>
<p>I highlighted the words &#8220;only&#8221; and &#8220;every&#8221; in the section on use cases to make a point: default_scope should be used with caution. The fact is, however, that it&#8217;s not an &#8220;only&#8221; and &#8220;every&#8221; world, and as such, we need work arounds. In our case, it&#8217;s by using &#8220;with_exclusive_scope&#8221; and the undocumented &#8220;unscoped&#8221; (Rails 3.x only)</p>
<p>with_exclusive_scope example:</p>
<pre name='code' class="ruby">Article.with_exclusive_scope { find(:all) }
</pre>
<p>unscoped example (Rails 3.x only):</p>
<pre name='code' class="ruby">Article.unscoped
</pre>
<h2>Conclusion</h2>
<p>In general, we like to keep our code as DRY as possible, but in cases like default_scope, we prefer to be more explicit. We recognize the value of default_scope, but only use it when we absolutely need to, and even then we try to think of alternative methods.</p>
<p>How about you? We would really like to hear from you about your experiences with default scopings. What considerations do you take into account when choosing whether or not to use default_scope?</p>
<h2>Further Reading</h2>
<ul>
<li><a href="http://ryandaigle.com/articles/2008/11/18/what-s-new-in-edge-rails-default-scoping">What&#8217;s New in Edge Rails: Default Scoping</a></li>
<li><a href="http://stackoverflow.com/questions/2073419/overriding-default-scope-in-rails">Overriding default_scope in Rails</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://databasically.com/2011/02/07/default_scope-use-cases-caveats-and-work-arounds/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What time is it? Or, handling timezones in Rails.</title>
		<link>http://databasically.com/2010/10/22/what-time-is-it-or-handling-timezones-in-rails/</link>
		<comments>http://databasically.com/2010/10/22/what-time-is-it-or-handling-timezones-in-rails/#comments</comments>
		<pubDate>Fri, 22 Oct 2010 03:46:59 +0000</pubDate>
		<dc:creator>Wes</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://databasically.com/?p=406</guid>
		<description><![CDATA[As a followup to a stack overflow answer, I thought I would give some examples of working with time zones in rails. What does Rails timezone support do for me? Stores everything in UTC in the database Allows you to set an application default timezone and/or timezones for your users Automatically converts UTC in the [...]]]></description>
			<content:encoded><![CDATA[<p>As a followup to a <a href="http://stackoverflow.com/questions/3993619/time-select-with-12-hour-time-and-time-zone-in-ruby-on-rails">stack overflow answer</a>, I thought I would give some examples of working with time zones in rails.</p>
<h3>What does Rails timezone support do for me?</h3>
<ul>
<li>Stores everything in UTC in the database</li>
<li>Allows you to set an application default timezone and/or timezones for your users</li>
<li>Automatically converts UTC in the database to the correct zone and back</li>
</ul>
<h3>What zones are available?</h3>
<p>You can get a list of timezones with rake tasks:</p>
<pre name="code" class="ruby"># Displays names of all time zones recognized by the Rails TimeZone class, grouped by offset.
rake time:zones:all

# Displays names of time zones recognized by the Rails TimeZone class with the same offset as the system local time
rake time:zones:local

# Displays names of US time zones recognized by the Rails TimeZone class, grouped by offset.
rake time:zones:us</pre>
<h3>Setting the default time zone</h3>
<p>In your environment.rb (Rails 2) or application.rb (Rails 3) file, you can set the default timezone:</p>
<pre name="code" class="ruby">config.time_zone = 'Central Time (US &amp; Canada)'</pre>
<p>What does this do?  By setting an application-wide timezone, any datetime will be stored in UTC in the database, but will be translated when we access it.</p>
<h3>Set a timezone for a user</h3>
<p>You can use <a href="http://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/time_zone_select">time_zone_select</a> to get a list of timezones for a user to pick from. The third argument is a list of &#8220;priority&#8221; zones that will appear first.</p>
<pre name="code" class="ruby"> time_zone_select( "user", 'time_zone', TimeZone.us_zones, :default =&gt; "Pacific Time (US &amp; Canada)")</pre>
<p>Once the value is saved in the database, you&#8217;ll want to set it for each request, per user:</p>
<pre name="code" class="ruby">  before_filter :set_timezone

  def set_timezone
    # current_user.time_zone #=&gt; 'Central Time (US &amp; Canada)'
    Time.zone = current_user.time_zone || 'Central Time (US &amp; Canada)'
  end</pre>
<p>[<strong>UPDATE</strong>: You'll need a field 'time_zone' in your user table!]</p>
<p>[<strong>UPDATE</strong>: You probably want to stay DRY and refer to the configured value instead of specifying the timezone value in both places: <br />Time.zone = current_user.time_zone || MyAppName::Application.config.time_zone]</p>
<p>Let me know if you have questions or improvements and I&#8217;ll integrate them into the article.  Thanks!</p>
]]></content:encoded>
			<wfw:commentRss>http://databasically.com/2010/10/22/what-time-is-it-or-handling-timezones-in-rails/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Getting the Runaround</title>
		<link>http://databasically.com/2010/10/21/getting-the-runaround/</link>
		<comments>http://databasically.com/2010/10/21/getting-the-runaround/#comments</comments>
		<pubDate>Thu, 21 Oct 2010 19:03:23 +0000</pubDate>
		<dc:creator>Samuel Mullen</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Factories]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://databasically.com/?p=379</guid>
		<description><![CDATA[Yesterday was my third day on the job and to be honest, it wasn&#8217;t a lot of fun. I&#8217;m learning a lot of things right now: a new project, new methodologies, and new technologies. Combine all of that with a seemingly useless RSpec error and you can imagine where my blood pressure was reaching. I [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday was my third day on the job and to be honest, it wasn&#8217;t a lot of fun. I&#8217;m learning a lot of things right now: a new project, new methodologies, and new technologies. Combine all of that with a seemingly useless RSpec error and you can imagine where my blood pressure was reaching.</p>
<p>I had just added a new association to a FactoryGirl factory. I&#8217;ve not used FactoryGirl before, but it&#8217;s easy enough to copy and paste from other factories in the directory. So far, so good. I wasn&#8217;t watching the test output, but it was just one line, what could go wrong?</p>
<p>Several updates and commits later, I thought I&#8217;d better make sure we were still &#8220;Green&#8221;. Eh, not so much. Here&#8217;s the output I was seeing repeated over and over again.</p>
<pre name="code" class="ruby">
Failure/Error: Unable to find matching line from backtrace
stack level too deep
# /home/user/.rvm/gems/ruby-1.9.2-p0@xxx/gems/activerecord-3.0.0/lib/active_record/locking/optimistic.rb:62
</pre>
<p>I&#8217;ll not bore you with the details of my fruitless search to track this down. Suffice it to say, Wes &#8211; that would be my new boss &#8211; helped me back out my changes and track down the error.</p>
<p>It turns out that my &#8220;simple&#8221; addition to the &#8220;facility&#8221; factory wasn&#8217;t so simple. It actually resulted in a never ending loop of weeping and gnashing of teeth.</p>
<p>There are three models which were being dealt with: Facility, User, and Department. Departments have many users; facilities have many departments, and a facility can have a user who is defined as a contact. The schema looks like this:</p>
<p><a href="http://databasically.com/wp-content/uploads/2010/10/roundabout.png"><img class="alignnone size-full wp-image-383" title="runaround" src="http://databasically.com/wp-content/uploads/2010/10/roundabout.png" alt="rounaround schema" width="485" height="326" /></a></p>
<p>In my &#8220;facility&#8221; factory, I was making an association to the &#8220;users&#8221; table. Unbeknownst to me, the &#8220;user&#8221; factory was making an association to &#8220;department&#8221;, which was in turn making an association to &#8220;facility&#8221;, which was making an association to &#8220;user&#8221;, ad nauseum. The result: a &#8220;stack level too deep&#8221; error.</p>
<p>The solution was to just create the user association with the &#8220;department&#8221; set to nil.</p>
<p>Before:<br />
<code><br />
t.association :contact, :factory =&gt; :user<br />
</code></p>
<p>After:<br />
<code><br />
t.association :contact, :factory =&gt; :user, :department =&gt; nil<br />
</code></p>
<p>Hopefully this will make someone else&#8217;s first week on the job go a little smoother and keep them from getting the runaround.</p>
]]></content:encoded>
			<wfw:commentRss>http://databasically.com/2010/10/21/getting-the-runaround/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Running rails migrations in other databases</title>
		<link>http://databasically.com/2010/09/24/running-rails-migrations-in-other-databases/</link>
		<comments>http://databasically.com/2010/09/24/running-rails-migrations-in-other-databases/#comments</comments>
		<pubDate>Fri, 24 Sep 2010 05:04:56 +0000</pubDate>
		<dc:creator>Wes</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://databasically.com/?p=374</guid>
		<description><![CDATA[We have a set of Ruby on Rails applications that shares user logins, so we put that table in a database and connect to it from each application. If an app needs to add a column to the shared table, you can create a migration that accesses that other database. First, create an entry in [...]]]></description>
			<content:encoded><![CDATA[<p>We have a set of Ruby on Rails applications that shares user logins, so we put that table in a database and connect to it from each application.</p>
<p>If an app needs to add a column to the shared table, you can create a migration that accesses that other database.   </p>
<p>First, create an entry in your <code>database.yml</code> file (we name ours &#8220;user_development&#8221;, etc.).</p>
<p>Then, establish that connection in your database migration and do your migration stuff:<br />
<script src="http://gist.github.com/594886.js"> </script></p>
<p>This has the benefit of keeping all the migrations local to the app they&#8217;re needed for, but it stores the schema of the users table in the users database where it belongs.</p>
]]></content:encoded>
			<wfw:commentRss>http://databasically.com/2010/09/24/running-rails-migrations-in-other-databases/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Converting erb to haml in rails3</title>
		<link>http://databasically.com/2010/09/19/converting-erb-to-haml-in-rails3/</link>
		<comments>http://databasically.com/2010/09/19/converting-erb-to-haml-in-rails3/#comments</comments>
		<pubDate>Sun, 19 Sep 2010 16:17:59 +0000</pubDate>
		<dc:creator>Wes</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://databasically.com/?p=370</guid>
		<description><![CDATA[I&#8217;m taking over a project that&#8217;s just started and prefer to use haml. In setting up my environment to work with rails3 and haml, here&#8217;s the best way I found to convert the fledgling app to haml. Install gems Run this This will convert all .erb files in app/views into .haml files right next to [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m taking over a project that&#8217;s just started and prefer to use haml. In setting up my environment to work with rails3 and haml, here&#8217;s the best way I found to convert the fledgling app to haml.</p>
<h2>Install gems</h2>
<p><script src="http://gist.github.com/586872.js?file=Gemfile"></script></p>
<h2>Run this</h2>
<p><script src="http://gist.github.com/586872.js?file=convert-to-haml.rb"></script></p>
<p>This will convert all .erb files in app/views into .haml files right next to them, leaving the originals in case you need to refer to them to fix somethig the converter missed.</p>
<p>This isn&#8217;t rails 3 specific, except for the Gemfile part, really.</p>
]]></content:encoded>
			<wfw:commentRss>http://databasically.com/2010/09/19/converting-erb-to-haml-in-rails3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>rspec2, rails3, and spork with drb to get faster tests</title>
		<link>http://databasically.com/2010/09/17/rspec2-rails3-and-spork-with-drb-to-get-faster-tests/</link>
		<comments>http://databasically.com/2010/09/17/rspec2-rails3-and-spork-with-drb-to-get-faster-tests/#comments</comments>
		<pubDate>Fri, 17 Sep 2010 01:52:12 +0000</pubDate>
		<dc:creator>Wes</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://databasically.com/?p=367</guid>
		<description><![CDATA[I started using rspec2 and rails3 on a project and wanted faster tests. Gemfile: gem 'spork' bundle install spork --bootstrap Bootstrapping will edit your spec_helper.rb file with some instructions. I had a vanilla spec_helper file, so everything got moved into the Spork.prefork block. Also, I&#8217;m using autotest, so I added --drb to my .rspec file. [...]]]></description>
			<content:encoded><![CDATA[<p>I started using rspec2 and rails3 on a project and wanted faster tests.</p>
<pre class="code" name="ruby">Gemfile:
gem 'spork'

bundle install

spork --bootstrap
</pre>
<p>Bootstrapping will edit your spec_helper.rb file with some instructions.  I had a vanilla spec_helper file, so everything got moved into the <code>Spork.prefork</code> block.</p>
<p>Also, I&#8217;m using autotest, so I added <code>--drb</code> to my .rspec file.</p>
<p>Finally:</p>
<pre class="code" name="ruby">
spork &#038;
autotest
</pre>
<p>I only had 15 tests at the time that I did this, but they went from running in 6 seconds to running in 1.5 seconds. Significant.</p>
<p><strong>UPDATE:</strong></p>
<p>From the comments, here&#8217;s a fix for running rake on Windows (&#8220;can&#8217;t find executable rake&#8221;):<br />
<script src="http://gist.github.com/519744.js"> </script></p>
]]></content:encoded>
			<wfw:commentRss>http://databasically.com/2010/09/17/rspec2-rails3-and-spork-with-drb-to-get-faster-tests/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

