<?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>dec0der &#187; rails</title>
	<atom:link href="http://blog.d27n.com/category/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.d27n.com</link>
	<description>the d27n blog</description>
	<lastBuildDate>Wed, 11 Jan 2012 21:08:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Rails has_many Time.now gotcha</title>
		<link>http://blog.d27n.com/2009/10/07/rails-has_many-time-now-gotcha/</link>
		<comments>http://blog.d27n.com/2009/10/07/rails-has_many-time-now-gotcha/#comments</comments>
		<pubDate>Thu, 08 Oct 2009 04:46:28 +0000</pubDate>
		<dc:creator>dryan</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[activerecord]]></category>
		<category><![CDATA[has_many]]></category>

		<guid isPermaLink="false">http://blog.d27n.com/?p=61</guid>
		<description><![CDATA[It&#8217;s one of those face palm moments for me, but don&#8217;t use has_many in your rails models if it&#8217;s time dependent data. In the production environment the Time.now will be the time the environment loads the class, which is only once per server start. Keep in mind your code will work in development and test [...]]]></description>
			<content:encoded><![CDATA[<div class="fblikebutton_button" style="float: right; margin-left: 10px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.d27n.com%2F2009%2F10%2F07%2Frails-has_many-time-now-gotcha%2F&amp;layout=standard&amp;show-faces=false&amp;width=450&amp;action=recommend&amp;colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:26px"></iframe>
		</div>
<p>It&#8217;s one of those face palm moments for me, but don&#8217;t use has_many in your rails models if it&#8217;s time dependent data.  In the production environment the Time.now will be the time the environment loads the class, which is only once per server start.  Keep in mind your code will work in development and test mode. So basically the solution is to move those has_many statements into a function.<br />
<code><br />
has_many :recent_stuff, :conditions =&gt; ["starts_at =?", Time.now]<br />
</code></p>
<p>becomes&#8230;<br />
<code><br />
def recent_stuff<br />
timenow = Time.now<br />
self.find(:all, :conditions =&gt; ["starts_at = ?", timenow])<br />
end<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.d27n.com/2009/10/07/rails-has_many-time-now-gotcha/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>They&#8217;re stealing your code!</title>
		<link>http://blog.d27n.com/2009/09/24/theyre-stealing-your-code/</link>
		<comments>http://blog.d27n.com/2009/09/24/theyre-stealing-your-code/#comments</comments>
		<pubDate>Thu, 24 Sep 2009 17:09:26 +0000</pubDate>
		<dc:creator>schmeeve</dc:creator>
				<category><![CDATA[apache]]></category>
		<category><![CDATA[pound]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://blog.d27n.com/?p=41</guid>
		<description><![CDATA[Block access to your code in .svn directories via Apache and the Pound load balancer]]></description>
			<content:encoded><![CDATA[<div class="fblikebutton_button" style="float: right; margin-left: 10px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.d27n.com%2F2009%2F09%2F24%2Ftheyre-stealing-your-code%2F&amp;layout=standard&amp;show-faces=false&amp;width=450&amp;action=recommend&amp;colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:26px"></iframe>
		</div>
<p>The great security scare of the day is rouge (possibly Russian!) thieves on the prowl looking for source code on your websitez by poking through repository directories, such as .svn. Anyway, it&#8217;s simple to block, but please folks, look at where your web servers are pointed and what may be exposed. It&#8217;s a problem as old as the web itself.</p>
<p>In Apache, this can be done easily:</p>
<blockquote><p><code>&lt;IfModule mod_rewrite.c&gt;<br />
  RewriteRule ^(.*/)?\.svn/ - [F,L]<br />
  ErrorDocument 403 "Access Forbidden"<br />
&lt;/IfModule&gt;</code></p></blockquote>
<p>But sitting in front of Apache and Mongrel we use the pound load balancer. Here&#8217;s a bit of code which will catch anything trying to get into the svn directory, even though directory listings weren&#8217;t possible in the first place:</p>
<blockquote><p><code>Service<br />
URL ".svn.*"<br />
Redirect "http://d27n.com/public/404.html"<br />
End</code></p></blockquote>
<p>You can even skip the Redirect if you want to be lazy or don&#8217;t have a 404 page. This will just deadend the service.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.d27n.com/2009/09/24/theyre-stealing-your-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>authlogic facebook-connect and rspec</title>
		<link>http://blog.d27n.com/2009/09/22/authlogic-facebook-connect-and-rspec/</link>
		<comments>http://blog.d27n.com/2009/09/22/authlogic-facebook-connect-and-rspec/#comments</comments>
		<pubDate>Tue, 22 Sep 2009 23:51:01 +0000</pubDate>
		<dc:creator>dryan</dc:creator>
				<category><![CDATA[authlogic]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[facebook connect]]></category>

		<guid isPermaLink="false">http://blog.d27n.com/?p=34</guid>
		<description><![CDATA[The past week I&#8217;ve had a chance to add facebook-connect to a rails site we&#8217;ve been working on by using the fantastic Authlogic and the Authlogic Facebook Connect add on.  However I found that all my existing controller tests blew up after adding the facebook-connect add on and after a little digging realized I needed [...]]]></description>
			<content:encoded><![CDATA[<div class="fblikebutton_button" style="float: right; margin-left: 10px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.d27n.com%2F2009%2F09%2F22%2Fauthlogic-facebook-connect-and-rspec%2F&amp;layout=standard&amp;show-faces=false&amp;width=450&amp;action=recommend&amp;colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:26px"></iframe>
		</div>
<p>The past week I&#8217;ve had a chance to add facebook-connect to a rails site we&#8217;ve been working on by using the fantastic <a title="authlogic" href="http://github.com/binarylogic/authlogic" target="_blank">Authlogic</a> and the <a title="Authlogic Facebook Connect" href="http://github.com/kalasjocke/authlogic_facebook_connect" target="_blank">Authlogic Facebook Connect</a> add on.  However I found that all my existing controller tests blew up after adding the facebook-connect add on and after a little digging realized I needed to stub a method on the  rspec TestRequest method.</p>
<p>The <a href="http://rdoc.info/rdoc/binarylogic/authlogic/blob/f2f6988d3b97e11770b00b72a7a9733df69ffa5b/Authlogic/TestCase.html" target="_blank">TestCase rdoc</a> explains how to setup authlogic within your rspec controller tests, so I won&#8217;t get into that here.  Since I already had everything setup with a login method in my spec_helper.rb file, I just had to add a single line to that method.</p>
<p><span style="font-family: monospace, 'Times New Roman', 'Bitstream Charter', Times, serif;">~/spec/spec_helper.rb</span></p>
<p><code></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco;"><span style="color: #b02b8e;">def</span> login(user)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; color: #f55358;"><span style="color: #000000;"> request.stub!(</span>:set_facebook_session<span style="color: #000000;">)</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco;">UserSession.create(users(user))</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; color: #b02b8e;">end</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; color: #b02b8e;">
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; color: #b02b8e;">
<p></code></p>
<p>Eventually I&#8217;ll have to write some tests for any features that use the facebook api, but for now stubbing that method does the trick.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.d27n.com/2009/09/22/authlogic-facebook-connect-and-rspec/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mac OS X Snow Leopard + Rails, MySQL, and Sphinx</title>
		<link>http://blog.d27n.com/2009/08/26/mac-os-x-snow-leopard-rails-mysql-and-sphinx/</link>
		<comments>http://blog.d27n.com/2009/08/26/mac-os-x-snow-leopard-rails-mysql-and-sphinx/#comments</comments>
		<pubDate>Wed, 26 Aug 2009 18:21:46 +0000</pubDate>
		<dc:creator>schmeeve</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[mac os x]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[rmagick]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[snow leopard]]></category>
		<category><![CDATA[sphinx]]></category>
		<category><![CDATA[ultrasphinx]]></category>

		<guid isPermaLink="false">http://blog.d27n.com/?p=14</guid>
		<description><![CDATA[Ah, Snow Leopard. While you&#8217;re admiring the photoshop job Apple did to the box art, you may be eager to install the new Leopard, but hang on if you&#8217;re using Rails. If you&#8217;re getting the following types of error with the mysql driver, you may need to reinstall. The error: !!! The bundled mysql.rb driver [...]]]></description>
			<content:encoded><![CDATA[<div class="fblikebutton_button" style="float: right; margin-left: 10px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.d27n.com%2F2009%2F08%2F26%2Fmac-os-x-snow-leopard-rails-mysql-and-sphinx%2F&amp;layout=standard&amp;show-faces=false&amp;width=450&amp;action=recommend&amp;colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:26px"></iframe>
		</div>
<p>Ah, <a href="http://www.amazon.com/gp/product/B001AMHWP8?ie=UTF8&amp;tag=d27ncom-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=B001AMHWP8" target="_blank">Snow Leopard</a>. While you&#8217;re admiring the <a href="http://gizmodo.com/5344970/original-snow-leopard-was-too-blood-thirsty-for-mac-os-x-box">photoshop job</a> Apple did to the box art, you may be eager to install the new Leopard, but hang on if you&#8217;re using Rails.</p>
<p>If you&#8217;re getting the following types of error with the mysql driver, you may need to reinstall.</p>
<h2>The error:</h2>
<blockquote><p><code>!!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql.<br />
rake aborted!<br />
dlopen(/Library/Ruby/Gems/1.8/gems/mysql-2.7/lib/mysql.bundle, 9): no suitable image found.  Did find:<br />
/Library/Ruby/Gems/1.8/gems/mysql-2.7/lib/mysql.bundle: mach-o, but wrong architecture - /Library/Ruby/Gems/1.8/gems/mysql-2.7/lib/mysql.bundle<br />
</code></p></blockquote>
<p>The fix:</p>
<blockquote><p><strong>
<pre>sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config</pre>
<p></strong></p></blockquote>
<p>(h/t <a href="http://stackoverflow.com/questions/991708/rails-mysql-and-snow-leopard" target="_blank">here</a>)</p>
<h2>Sphinx/Ultrasphinx:</h2>
<p>If sphinx is already installed (and searchd starts up without issue), you may be set. However, if you&#8217;re installing it new, you&#8217;ll want to compile it in 32-bit mode:</p>
<p>Download the latest tarball of Sphinx <a href="http://www.sphinxsearch.com/downloads.html" target="_blank">here</a>.</p>
<blockquote>
<pre><strong>./configure CFLAGS="-O -arch i386" CXXFLAGS="-O -arch i386" LDFLAGS="-arch i386" --disable-dependency-tracking
make
make install</strong></pre>
</blockquote>
<h2>RMagick:</h2>
<p>NOTE: Despite trying <a href="http://www.agileanimal.com/2009/08/11/imagemagick-and-rmagick-on-leopard-and-other-large-white-cats" target="_blank">this</a>, I still am having issues with RMagick. If anyone&#8217;s got tips&#8230;</p>
<p><strong>UPDATE:</strong> As per Dimitri&#8217;s (big hat tip!) post below, I *finally* got everything going using MacPorts, which I hadn&#8217;t realized was updated for Snow Leopard yet.</p>
<p>Didn&#8217;t go so smoothly, but finally succeeded. Just threw in the towel and got my old MacPorts install out of the way and started over.</p>
<p>To uninstall MacPorts completely (<strong>big caveat: this will uninstall everything previously installed with MacPorts</strong>):</p>
<blockquote><pre>sudo port -f uninstall installed

sudo rm -rf /opt/local \
/Applications/MacPorts \
/Applications/DarwinPorts \
/Library/Tcl/macports1.0 \
/Library/Tcl/darwinports1.0 \
/Library/LaunchDaemons/org.macports.* \
/Library/StartupItems/DarwinPortsStartup \
/Library/Receipts/MacPorts*.pkg \
/Library/Receipts/DarwinPorts*.pkg \
~/.macports</pre>
</blockquote>
<p>Then installed libxml2 and ImageMagick as Dimitri recommends, followed by:</p>
<blockquote><pre>sudo port install rb-rubygems
sudo gem install rmagick
</pre>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://blog.d27n.com/2009/08/26/mac-os-x-snow-leopard-rails-mysql-and-sphinx/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using memcached
Object Caching 743/791 objects using memcached

Served from: blog.d27n.com @ 2012-02-05 12:10:14 -->
