<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <title>TangoFoxtrot - Blog</title>
  <id>tag:tangofoxtrot.com,2008:mephisto/</id>
  <generator uri="http://mephistoblog.com" version="0.8.0">Mephisto Drax</generator>
  <link href="http://tangofoxtrot.com/feed/atom.xml" rel="self" type="application/atom+xml"/>
  <link href="http://tangofoxtrot.com/" rel="alternate" type="text/html"/>
  <updated>2008-05-08T20:46:55Z</updated>
  <entry xml:base="http://tangofoxtrot.com/">
    <author>
      <name>Richard</name>
    </author>
    <id>tag:tangofoxtrot.com,2008-05-08:8</id>
    <published>2008-05-08T20:46:00Z</published>
    <updated>2008-05-08T20:46:55Z</updated>
    <category term="plugins"/>
    <category term="rails"/>
    <category term="ruby"/>
    <category term="save_without_callbacks"/>
    <link href="http://tangofoxtrot.com/2008/5/8/active-record-save-without-callbacks-plugin" rel="alternate" type="text/html"/>
    <title>Active Record - Save without Callbacks Plugin</title>
<content type="html">
            &lt;p&gt;There are a few times, not many, when you really don't want to trigger AR callbacks on a save. Take the following simple example:&lt;/p&gt;
&lt;pre&gt;
class Article &amp;lt; ActiveRecord::Base
  include ActionView::Helpers::SanitizeHelper
  before_save :sanitize_body_text

  def sanitize_body_text
     self.body_text = sanitize(self.body_text)
  end
end

article.update_attribute(:posted_at, Time.now - 100)
&lt;/pre&gt;
&lt;p&gt;You probably don't want to fire up an expensive method like sanitize when updating the posted_at time.&lt;/p&gt;

&lt;p&gt;save_without_callbacks solves that problem.&lt;/p&gt; 

&lt;p&gt;To Install&lt;/p&gt;
&lt;pre&gt;
./script/plugin install https://tangofoxtrot.com/svn/plugins/save_without_callbacks
&lt;/pre&gt;

&lt;p&gt;On any AR.object that you want to skip the callbacks for: &lt;/p&gt;
&lt;pre&gt;
@something.skip_callbacks = true
&lt;/pre&gt;
&lt;p&gt;&lt;i&gt;*note you cannot set this on mass assignment*&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;Then call:&lt;/p&gt;

&lt;pre&gt;@something.save&lt;/pre&gt;
&lt;p&gt;&amp;lt;u&gt;This plugin can be potentially dangerous! Make sure this is the behavior you want.&amp;lt;/u&gt;&lt;/p&gt;

&lt;p&gt;For example acts_as_list:&lt;/p&gt;
&lt;pre&gt;
before_create  :add_to_list_bottom
before_destroy :remove_from_list

def remove_from_list
  if in_list?
    decrement_positions_on_lower_items
    update_attribute position_column, nil
  end
end
&lt;/pre&gt;
&lt;p&gt;If you set skip_callbacks to true and updated the position or created/destroyed an object the positions will be off.&lt;/p&gt;

&lt;p&gt;This is best used in a situation where you are updating some arbitrary, non relationship, data.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://tangofoxtrot.com/">
    <author>
      <name>Richard</name>
    </author>
    <id>tag:tangofoxtrot.com,2008-05-08:7</id>
    <published>2008-05-08T16:58:00Z</published>
    <updated>2008-05-08T17:03:53Z</updated>
    <category term="rails"/>
    <category term="ruby"/>
    <link href="http://tangofoxtrot.com/2008/5/8/simple-explaination-of-alias_method_chain" rel="alternate" type="text/html"/>
    <title>Simple Explanation of alias_method_chain</title>
<content type="html">
            &lt;p&gt;If you are new to rails you've probably seen the method alias_method_chain but dont know exactly what it does. Here is simplified example. &lt;/p&gt;
&lt;pre&gt;
require 'rubygems'
require 'active_support'

class Breakfast
  def cereal
    &quot;Lucky Charms&quot;
  end
end

Produces:
irb(main):003:0&gt; Breakfast.new.cereal
=&gt; &quot;Lucky Charms&quot;
&lt;/pre&gt;
&lt;p&gt;Nothing exotic here. Just a breakfast class with one method. Lets bring in alias_method_chain.&lt;/p&gt;
&lt;p&gt;For that we will need to have a method to 'alias to'. &lt;/p&gt;

&lt;pre&gt;
module Milk
  
  def self.included(base)
    base.alias_method_chain :cereal, :milk
  end
  
  def cereal_with_milk
    &quot;Milk and #{cereal_without_milk}&quot;
  end
  
end
&lt;/pre&gt;
&lt;p&gt;The previous code does the following:&lt;/p&gt;
&lt;ol&gt;
 &lt;li&gt;Creates an alias (think shortcut) to the method 'cereal' with the name 'cereal_without_milk'&lt;/li&gt;
 &lt;li&gt;Creates another alias for cereal_with_milk with the name 'cereal'&lt;/li&gt;
 &lt;li&gt;Defines the method cereal_with_milk&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now when we call the method breakfast.cereal our newly created action, 'cereal_with_milk' will be called. The code in action:&lt;/p&gt;
&lt;pre&gt;
irb(main):002:0&gt; Breakfast.send(:include, Milk)
=&gt; Breakfast
irb(main):003:0&gt; Breakfast.new.cereal
=&gt; &quot;Milk and Lucky Charms&quot;
&lt;/pre&gt;
&lt;p&gt;The end result, we have milk with our Lucky Charms.&lt;/p&gt;

&lt;p&gt;Download the original Code: &lt;a href=&quot;http://tangofoxtrot.com/assets/2008/5/8/alias_method_chain_example.rb&quot;&gt;alias_method_chain_example.rb&lt;/a&gt;&amp;lt;/p
          </content>  </entry>
  <entry xml:base="http://tangofoxtrot.com/">
    <author>
      <name>Richard</name>
    </author>
    <id>tag:tangofoxtrot.com,2008-02-07:4</id>
    <published>2008-02-07T01:09:00Z</published>
    <updated>2008-02-07T01:43:50Z</updated>
    <category term="plugins"/>
    <category term="rails"/>
    <category term="xhr_rescue_handler"/>
    <link href="http://tangofoxtrot.com/2008/2/7/xhr-error-catching" rel="alternate" type="text/html"/>
    <title>Xhr Error Catching</title>
<content type="html">
            &lt;p&gt;
  &lt;img class=&quot;flushRight&quot; src=&quot;http://tangofoxtrot.com/assets/2008/2/7/Picture_1.png&quot; /&gt;One of the more common questions I see from new rails developers is &quot;Clicking an ajax link doesnt do anything.&quot; Most web developers use the web developer toolbar extension for firefox (&lt;a href=&quot;https://addons.mozilla.org/en-US/firefox/addon/60&quot;&gt;Here&lt;/a&gt;). Even then its easy to miss the error message that pops up in console.
&lt;/p&gt;
&lt;br /&gt;
&lt;p&gt;
  &lt;img class=&quot;flushLeft&quot; src=&quot;http://tangofoxtrot.com/assets/2008/2/7/Picture_2.png&quot; /&gt;I created a simple plugin which will check to see if you made an xhr request, if so it will render the error to a file then bring up a javascript confirm box asking if you want to see the error.
&lt;/p&gt;

&lt;p&gt;Should be a drop in replacement for rails 2.0.2 and 1.2.6.&lt;/p&gt;

&lt;p class=&quot;response&quot;&gt;script/plugin install http://tangofoxtrot.com/svn/plugins/xhr_rescue_handler&lt;/p&gt;

&lt;p&gt;This is my first plugin so please feel free to tear it apart.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://tangofoxtrot.com/">
    <author>
      <name>Richard</name>
    </author>
    <id>tag:tangofoxtrot.com,2008-01-30:3</id>
    <published>2008-01-30T02:13:00Z</published>
    <updated>2008-01-30T03:50:41Z</updated>
    <category term="pics"/>
    <category term="ramblings"/>
    <link href="http://tangofoxtrot.com/2008/1/30/never-thought-id-see-the-day-when" rel="alternate" type="text/html"/>
    <title>Never thought Id see the day when...</title>
<content type="html">
            &lt;img class=&quot;flushLeft&quot; src=&quot;http://www.tangofoxtrot.com/assets/2008/1/30/icons.jpg&quot; /&gt; The Microsoft Office Mac icons look better than the Adobe Suite icons.
          </content>  </entry>
  <entry xml:base="http://tangofoxtrot.com/">
    <author>
      <name>Richard</name>
    </author>
    <id>tag:tangofoxtrot.com,2008-01-25:2</id>
    <published>2008-01-25T23:58:00Z</published>
    <updated>2008-01-26T00:33:34Z</updated>
    <category term="ramblings"/>
    <link href="http://tangofoxtrot.com/2008/1/25/quick-intro" rel="alternate" type="text/html"/>
    <title>Quick Intro</title>
<content type="html">
            &lt;b&gt;Who is your daddy and what does he do?&lt;/b&gt;
&lt;p class=&quot;response&quot;&gt;My name is Richard, I am a Ruby/Ruby on Rails developer&lt;/p&gt;
&lt;b&gt;You think you're too cool for school?&lt;/b&gt;
&lt;p class=&quot;response&quot;&gt;No not really, Im just another fool with a blog&lt;/p&gt;
&lt;b&gt;What should I expect to find here?&lt;/b&gt;
&lt;p class=&quot;response&quot;&gt;Mostly posts about ruby/rails or design&lt;/p&gt;
          </content>  </entry>
</feed>
