<?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>Patrick Tulskie &#187; rails</title>
	<atom:link href="http://www.patricktulskie.com/tag/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.patricktulskie.com</link>
	<description>Building a Better Internet</description>
	<lastBuildDate>Wed, 16 Jun 2010 19:12:25 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Change ActiveRecord Pool Size on the Fly</title>
		<link>http://www.patricktulskie.com/2010/06/change-activerecord-pool-size-on-the-fly/</link>
		<comments>http://www.patricktulskie.com/2010/06/change-activerecord-pool-size-on-the-fly/#comments</comments>
		<pubDate>Wed, 16 Jun 2010 19:12:25 +0000</pubDate>
		<dc:creator>Patrick Tulskie</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ActiveRecord]]></category>
		<category><![CDATA[connection]]></category>
		<category><![CDATA[connection_pool]]></category>
		<category><![CDATA[pool]]></category>
		<category><![CDATA[pool size]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://www.patricktulskie.com/?p=168</guid>
		<description><![CDATA[I have a rake task that runs using the application&#8217;s production environment.  Unlike the production environment though, it is threaded.  In order to make any real use out of that, I need to increase the ActiveRecord connection pool size.  Normally you&#8217;d do this in your database.yml, but in this case I&#8217;d rather [...]]]></description>
			<content:encoded><![CDATA[<p>I have a rake task that runs using the application&#8217;s production environment.  Unlike the production environment though, it is threaded.  In order to make any real use out of that, I need to increase the ActiveRecord connection pool size.  Normally you&#8217;d do this in your database.yml, but in this case I&#8217;d rather not modify the production environment&#8217;s settings for the sake of a single rake task.</p>
<p>Here&#8217;s how you can make the change, on the fly, inside of your rake task:</p>
<pre><code>task :swimming_pool => :environment do
  ActiveRecord::Base.connection_pool.instance_variable_set('@size', 15)
  ActiveRecord::Base.connection_pool.instance_variable_set('@timeout', 10)
  # Do awesome threaded stuff here
end
</code></pre>
<p>The first line of the rake task increases your pool size and the second line changes your timeout when waiting for a connection from the pool.  You can adjust those values to whatever you need.  That just happened to be what I need for this particular task.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.patricktulskie.com/2010/06/change-activerecord-pool-size-on-the-fly/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Skip Rails AuthenticityToken Check, Sometimes</title>
		<link>http://www.patricktulskie.com/2010/04/skip-rails-authenticitytoken-check-sometimes/</link>
		<comments>http://www.patricktulskie.com/2010/04/skip-rails-authenticitytoken-check-sometimes/#comments</comments>
		<pubDate>Wed, 07 Apr 2010 16:05:10 +0000</pubDate>
		<dc:creator>Patrick Tulskie</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[authenticitytoken]]></category>
		<category><![CDATA[before_filter]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[request]]></category>

		<guid isPermaLink="false">http://www.patricktulskie.com/?p=154</guid>
		<description><![CDATA[Earlier today, Elad Meidar asked on Twitter about how to bypass checking the Authenticity Token in Rails for an action, sometimes.  The example he mentioned was for a write API but this could theoretically be used for other situations where you only want to skip the authenticity token check of an action under specific [...]]]></description>
			<content:encoded><![CDATA[<p>Earlier today, Elad Meidar asked on <a href="http://twitter.com/eladmeidar/status/11759280546">Twitter</a> about how to bypass checking the Authenticity Token in Rails for an action, sometimes.  The example he mentioned was for a write API but this could theoretically be used for other situations where you only want to skip the authenticity token check of an action under specific circumstances.  We went back and fort</p>
<p>
First off, you need to do some before filter work:</p>
<pre><code>skip_before_filter :verify_authenticity_token, :only => [:your_action]
before_filter :semi_verify_authenticity_token, :only => [:your_action]</code></pre>
</p>
<p>
Then you need a function to define when to check for the token authenticity:</p>
<pre><code>def semi_verify_authenticity_token
  verify_authenticity_token unless request.xhr? # Or whatever other criteria you would use
end</code></pre>
</p>
<p>All you really have to do then is make sure that verify_authenticity_token gets called based on the params or request and you should be set.  This can be useful for APIs or AJAX calls calls to a given action where you don&#8217;t mind skipping the token check, but you still want to enforce it for the regular HTML browser view.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.patricktulskie.com/2010/04/skip-rails-authenticitytoken-check-sometimes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby String#Nameize Revised</title>
		<link>http://www.patricktulskie.com/2008/12/ruby-string-nameize-revised/</link>
		<comments>http://www.patricktulskie.com/2008/12/ruby-string-nameize-revised/#comments</comments>
		<pubDate>Tue, 30 Dec 2008 19:10:31 +0000</pubDate>
		<dc:creator>Patrick Tulskie</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[irish]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[mc]]></category>
		<category><![CDATA[nameize]]></category>
		<category><![CDATA[names]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[string]]></category>

		<guid isPermaLink="false">http://www.patricktulskie.com/?p=102</guid>
		<description><![CDATA[Ruby String class extension to capitalize names properly, including Irish names with Mc, Mac, and O' in them.]]></description>
			<content:encoded><![CDATA[<p>This morning, Kevin Glowacz (<a href="http://twitter.com/kevinglowacz">@kevinglowacz</a>) replied to me a few times on Twitter about Ruby String#Nameize class extension I had posted a while back.  I had done some work to it after posting it here.  Kevin also asked me a few questions about oddities that were in it that have since been resolved.  So thanks to his prodding, you get a slightly updated version&#8230;</p>
<p>The only real &#8220;feature&#8221; is that it will now handle full names just fine. Otherwise, the rest of the stuff was mostly performance related.  Here it is:</p>
<pre><code>class String
  # Extension of the string class to properly handle camel names
  def nameize
    if self.match(/ /)
      # If the name has a space in it, we gotta run the parts through the nameizer.
      name = self.split(' ').each { |part| part.nameize! }.join(' ')
      return name
    elsif self.match(/^[A-Z]/)
      # If they took the time to capitalize their name then let's just jump out.
      return self
    else
      # If there are no spaces and there is no prior
      # capitalization then let's downcase the whole thing.
      name = self.downcase
    end
    # Let's now assume that they were lazy...
    return case
    when name.match(/^mac/)
      name.gsub(/^mac/, "").capitalize.insert(0, "Mac")
    when name.match(/^mc/)
      name.gsub(/^mc/, "").capitalize.insert(0, "Mc")
    when name.match(/^o\'/)
      name.split("'").each{ |piece| piece.capitalize! }.join("'")
    else
      name.capitalize # name is a first name or it's not Irish then capitalize it.
    end
  end

  def nameize!
    replace nameize # BANG!
  end

end</code></pre>
<p>As always &#8211; question, comments, suggestions &#8211; shoot me an email, leave a comment, or hit me on Twitter (@PatrickTulskie).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.patricktulskie.com/2008/12/ruby-string-nameize-revised/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Leopard and MySQL Gem</title>
		<link>http://www.patricktulskie.com/2008/11/leopard-and-mysql-gem/</link>
		<comments>http://www.patricktulskie.com/2008/11/leopard-and-mysql-gem/#comments</comments>
		<pubDate>Thu, 06 Nov 2008 18:48:14 +0000</pubDate>
		<dc:creator>Patrick Tulskie</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[gem]]></category>
		<category><![CDATA[leopard]]></category>
		<category><![CDATA[leopard mysql gem]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[os x]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby gem mysql rails]]></category>

		<guid isPermaLink="false">http://www.patricktulskie.com/?p=88</guid>
		<description><![CDATA[Explains how to get the MySQL ruby gem to compile for Macs on OS X Leopard.]]></description>
			<content:encoded><![CDATA[<p>Those of you doing rails development work on Leopard with MySQL have probably seen this error message when starting your app:</p>
<blockquote><p>WARNING: You&#8217;re using the Ruby-based MySQL library that ships with Rails. This library is not suited for production. Please install the C-based MySQL library instead (gem install mysql).</p></blockquote>
<p>Normally I don&#8217;t care, but I figured since I was doing some cleanup today and getting things ready to move on to a longer term it might be good to have a properly working MySQL gem.  I like to run with a system that is close to what we run production.  The closer you get, the less surprises you have when you push it live.</p>
<p><span id="more-88"></span></p>
<p><strong>More Fixing.  Less Talking.</strong></p>
<p>Damn you&#8217;re so pushy sometimes.  Anyhow.  I did a sudo gem install mysql and got another damn error.</p>
<pre><code>Building native extensions.  This could take a while...
ERROR:  Error installing mysql:
ERROR: Failed to build gem native extension.

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb install mysql
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... no
checking for mysql_query() in -lmysqlclient... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.
</code></pre>
<p>Oh good.  Another error.  Perfect.  I searched around the interwebs and someone suggested using &#8220;&#8211;with-mysql-lib=/usr/local/mysql/lib&#8221; in the options since that&#8217;s where the libraries are located.  It still barfed on me with that.</p>
<p><strong>A Solution Please.</strong></p>
<p>A few more minutes of hunting and pecking and I found the golden command:</p>
<pre><code>sudo gem install mysql -- --with-mysql-config
Building native extensions.  This could take a while...
Successfully installed mysql-2.7
1 gem installed</code></pre>
<p>Now I don&#8217;t have any errors when starting my rails applications that use MySQL and I&#8217;m closer to what I have in production.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.patricktulskie.com/2008/11/leopard-and-mysql-gem/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
