<?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>Big Dave's Blog &#187; rails</title>
	<atom:link href="http://davedupre.com/tag/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://davedupre.com</link>
	<description>Some random thoughts - Go big or stay home!</description>
	<lastBuildDate>Fri, 25 Jun 2010 15:50:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Checkout Hoptoad by thoughtbot, inc.</title>
		<link>http://davedupre.com/2009/06/15/checkout-hoptoad-by-thoughtbot-inc/</link>
		<comments>http://davedupre.com/2009/06/15/checkout-hoptoad-by-thoughtbot-inc/#comments</comments>
		<pubDate>Mon, 15 Jun 2009 11:00:12 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[errors]]></category>
		<category><![CDATA[hoptoad]]></category>
		<category><![CDATA[workling]]></category>

		<guid isPermaLink="false">http://davedupre.com/?p=370</guid>
		<description><![CDATA[I&#8217;ve been using Hoptoad for about two months now, and I&#8217;m sold. Hoptoad is a product by thoughbot, inc. Previously, I&#8217;ve always used the excellent exception_notification plugin. The exception_notification plugin is easy to use, and it works great. However, there are a couple of problems with it. You could flood your inbox if there is [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://hoptoadapp.com/welcome"><img class="alignnone" title="Hoptoad Logo" src="http://hoptoadapp.com/images/logo.png" alt="" width="252" height="94" /></a> I&#8217;ve been using <a href="http://hoptoadapp.com/welcome">Hoptoad</a> for about two months now, and I&#8217;m sold. Hoptoad is a product by <a href="http://www.thoughtbot.com/">thoughbot, inc</a>. Previously, I&#8217;ve always used the excellent <a href="http://github.com/rails/exception_notification/tree/master">exception_notification</a> plugin. The exception_notification plugin is easy to use, and it works great. However, there are a couple of problems with it.</p>
<ol>
<li>You could flood your inbox if there is a bad problem on a popular page.</li>
<li>It&#8217;s difficult to collect all the emails and track errors.</li>
</ol>
<p>Enter Hoptoad. Hoptoad solves both problems, and it is super simple to use and setup. It&#8217;s free for one project and two users. If that isn&#8217;t enough for you, the premium services are very reasonable.</p>
<p>How does it solve both problems? First, Hoptoad will still send you an email when there is an error. However, it won&#8217;t flood your inbox if there are hundreds of the same email. Second, Hoptoad provides a simple web-based system that groups your errors by exception class. That makes it easier to track down problems. Finally, you can mark errors resolved so you don&#8217;t have to wade through noise to solve the real problems.</p>
<p>Hoptoad installation:</p>
<p><strong>REMOVE EXCEPTION_NOTIFIER</strong></p>
<ol>
<li>In your ApplicationController, REMOVE this line:include ExceptionNotifiable</li>
<li>In your config/environment* files, remove all references to ExceptionNotifier.</li>
<li>Remove the vendor/plugins/exception_notifier directory.</li>
</ol>
<p><strong>INSTALL HOPTOAD_NOTIFIER</strong></p>
<p>From your project&#8217;s RAILS_ROOT, run:</p>
<p>script/plugin install git://github.com/thoughtbot/hoptoad_notifier.git</p>
<p><strong>CONFIGURATION</strong></p>
<p>You should have something like this in config/initializers/hoptoad.rb.</p>
<pre>HoptoadNotifier.configure do |config|
  config.api_key = '1234567890abcdef'  # You get your key when you sign up
end</pre>
<p>(Please note that this configuration should be in a global configuration, and is <strong>not</strong> enrivonment-specific. Hoptoad is smart enough to know what errors are caused by what environments, so your staging errors don&#8217;t get mixed in with your production errors.)</p>
<p>Once you do the above, any Exception not caught by your controllers will be sent to Hoptoad where where they can be aggregated, filtered, sorted, analyzed, massaged, and searched.</p>
<p>Now, if you have read anything I&#8217;ve done before, you know I do a lot of asynchronous processing with <a href="http://davedupre.com/2008/03/25/ruby-background-tasks-with-starling/">Workling</a>. By default, Hoptoad will not log errors from anything outside of your controllers. Fear not. Hoptoad provides a webservice API to send errors. Here is an example.</p>
<p>In workling/lib/workling/base.rb:</p>
<pre>    # takes care of suppressing remote errors but raising Workling::WorklingNotFoundError
    # where appropriate. swallow workling exceptions so that everything behaves like remote code.
    # otherwise StarlingRunner and SpawnRunner would behave too differently to NotRemoteRunner.
    def dispatch_to_worker_method(method, options)
      begin
        self.send(method, options)
      rescue Exception =&gt; e
        raise e if e.kind_of? Workling::WorklingError
        logger.error "Workling Error: runner could not invoke #{ self.class }:#{ method } with #{ options.inspect }. error was: #{ e.inspect }\n #{ e.backtrace.join("\n") }"
        # DND: Let HopToad know of the issue
        params = options || {}
        HoptoadNotifier.notify(
          :error_class =&gt; "Workling Error - #{e.class.name}",
          :error_message =&gt; "Workling Error(#{e.class.name}): #{e.message}",
          :request =&gt; { :params =&gt; params.merge(:worker_class =&gt; self.class.name, :worker_method =&gt; method) })
        # DND: end of change
      end
    end</pre>
<p>Now, any error not caught by your workers will be sent to Hoptoad for processing. You can use a similar method from Rake tasks or any scripts that run outside of controllers. Remember, Hoptoad will collect errors by :error_class, so you can use different classes to separate errors into bins based on where they came from.</p>
<p>Give Hoptoad a try. You will not be disappointed.</p>
]]></content:encoded>
			<wfw:commentRss>http://davedupre.com/2009/06/15/checkout-hoptoad-by-thoughtbot-inc/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Gotcha with find_each and find_in_batches</title>
		<link>http://davedupre.com/2009/05/20/gotcha-with-find_each-and-find_in_batches/</link>
		<comments>http://davedupre.com/2009/05/20/gotcha-with-find_each-and-find_in_batches/#comments</comments>
		<pubDate>Thu, 21 May 2009 03:26:26 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[find_each]]></category>
		<category><![CDATA[find_in_batches]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[with_scope]]></category>

		<guid isPermaLink="false">http://davedupre.com/?p=315</guid>
		<description><![CDATA[Rails 2.3 added a couple of nice new methods &#8211; find_each and find_in_batches. Both methods accomplish the same thing in a slightly different way. Unlike a normal finder these methods grab objects in batches instead of all at once. For instance, if you have 500,000 users, you don&#8217;t want to do the following: User.find(:all).each { [...]]]></description>
			<content:encoded><![CDATA[<p>Rails 2.3 added a couple of nice new methods &#8211; find_each and find_in_batches. Both methods accomplish the same thing in a slightly different way. Unlike a normal finder these methods grab objects in batches instead of all at once. For instance, if you have 500,000 users, you don&#8217;t want to do the following:</p>
<pre>User.find(:all).each { |user| user.some_method }</pre>
<p>The reason is that you just loaded all 500,000 records into memory, and your server is not happy. Instead, you could do:</p>
<pre>User.find_each { |user| user.some_method }</pre>
<p>By default, the above will only load 1,000 User objects into memory, and your server will thank you. If 1,000 is too big/small for you, use the :batch_size option to change it. The find_in_batches method is similar except that it provides the array to the block instead of one object at a time. For example:</p>
<pre>User.find_in_batches do |users|
  users.each { |user| user.some_method }
end</pre>
<p>If you ever used the wonderful <a href="http://github.com/mislav/will_paginate/tree/master">will_paginate</a> gem, you are probably familiar with the concept from the paginated_each method that will_paginate provided.</p>
<p>So, what is the problem? The problem is that you have to aware that unlike paginate_each, find_each and find_in_batches work by setting up a with_scope block. Therefore, if you need to do any other finds on that same model, the scope will apply. Usually this only affects relationships, but it isn&#8217;t hard to forget. Here is an example:</p>
<pre># This is a purely made up example
class User &lt; ActiveRecord::Base
  # There is a last_login_at attribute
  named_scope :recent_login,
              lambda { |*args|
              { :conditions =&gt; ["people.last_login_at &gt;= ?", (args.first || 1.week.ago)] } }
  belongs_to :parent, :class_name =&gt; "User", :foreign_key =&gt; "parent_id"
end </pre>
<pre>User.recent_login.find_each do |user|
  parent = user.parent # This will include the recent_login scope.
end </pre>
<p>It&#8217;s no different than other with_scope issues, but it isn&#8217;t as obvious. You can get around it by doing:</p>
<pre>User.recent_login.find_each do |user|
  # Got use send because with_excusive_scope is protected.
  User.send(:with_exclusive_scope)
    parent = user.parent # This will include the recent_login scope
  end
end</pre>
<p>Now, go and be kind to your server with find_each and find_in_batches &#8211; just remember the scope.</p>
]]></content:encoded>
			<wfw:commentRss>http://davedupre.com/2009/05/20/gotcha-with-find_each-and-find_in_batches/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
