<?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>omgsean.com &#187; Rails</title>
	<atom:link href="http://omgsean.com/category/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://omgsean.com</link>
	<description>It's a Site on the Internet</description>
	<lastBuildDate>Thu, 08 Oct 2009 03:53:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Overriding Paperclip Defaults for your Entire Rails App</title>
		<link>http://omgsean.com/2009/02/overriding-paperclip-defaults-for-your-entire-rails-app/</link>
		<comments>http://omgsean.com/2009/02/overriding-paperclip-defaults-for-your-entire-rails-app/#comments</comments>
		<pubDate>Wed, 18 Feb 2009 21:25:52 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Paperclip]]></category>

		<guid isPermaLink="false">http://omgsean.com/?p=21</guid>
		<description><![CDATA[Paperclip is hands-down the best file attachment plugin for Rails.  File_column was alright a while back, and attachment_fu was a frustrating mess.  One thing I don&#8217;t like about Paperclip though is that by default it fills your public folder with uploads.  (NOTE: As of the latest version of Paperclip this is no longer true.) This [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://thoughtbot.com/projects/paperclip" target="_blank">Paperclip</a> is hands-down the best file attachment plugin for Rails.  File_column was alright a while back, and attachment_fu was a frustrating mess.  One thing I don&#8217;t like about Paperclip though is that by default it fills your public folder with uploads.  (NOTE: As of the latest version of Paperclip this is no longer true.)  This is even worse if you have an attachment called &#8220;images&#8221; as they just get dropped into your images folder.</p>
<p>While it&#8217;s fairly easy to redefine where the attachments get saved on a per-model basis with the :url and :path options, I very much prefer to do something once and then never have to think about it again.  (This preference is part of the reason that this is only my second post on a blog I&#8217;ve had since December.)  Thankfully, overriding the defaults for your entire app is easy.  Just make a file called <strong>paperclip_defaults.rb</strong> in your config/initializers directory and fill it with the following lovely code:</p>
<pre><code>module Paperclip
  class Attachment
    def self.default_options
      @default_options ||= {
        :url           =&gt; "/system/:class/:attachment/:id/:style/:basename.:extension",
        :path          =&gt; ":rails_root/public/system/:class/:attachment/:id/:style/:basename.:extension",
        :styles        =&gt; {},
        :default_url   =&gt; "/:attachment/:style/missing.png",
        :default_style =&gt; <img src='http://omgsean.com/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> riginal,
        :validations   =&gt; [],
        :storage       =&gt; :filesystem
      }
    end
  end
end</code></pre>
<p>Just change the options in that block to suit your fancy, and the changes will take place across your entire application.</p>
]]></content:encoded>
			<wfw:commentRss>http://omgsean.com/2009/02/overriding-paperclip-defaults-for-your-entire-rails-app/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Targetting associated tables in an ActiveRecord conditions hash</title>
		<link>http://omgsean.com/2009/02/targetting-associated-tables-in-an-activerecord-conditions-hash/</link>
		<comments>http://omgsean.com/2009/02/targetting-associated-tables-in-an-activerecord-conditions-hash/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 18:23:34 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[ActiveRecord]]></category>

		<guid isPermaLink="false">http://omgsean.com/?p=3</guid>
		<description><![CDATA[Using a conditions hash isn&#8217;t always my favourite way to write finds in Rails, but in certain cases it&#8217;s an indispensible tool for building queries.  It&#8217;s especially handy when you&#8217;re building an advanced search where conditions may or may not be present. Recently I ran into an issue where I needed to run conditions on [...]]]></description>
			<content:encoded><![CDATA[<p>Using a conditions hash isn&#8217;t always my favourite way to write finds in Rails, but in certain cases it&#8217;s an indispensible tool for building queries.  It&#8217;s especially handy when you&#8217;re building an advanced search where conditions may or may not be present.</p>
<p>Recently I ran into an issue where I needed to run conditions on an associated table in just such a search and I managed to find what seems to be an undocumented (or under-documented at least) feature of ActiveRecord.  For the sake of using the same example as every other Rails tutorial out there, let&#8217;s assume that I&#8217;m running a search on Authors, and that an Author has_many books.  All we have to do is make a hash within the conditions hash with the name of the associated table.  Searching both tables is easy as:</p>
<pre><code>Author.find(:conditions => {:first_name => params[:first_name], :last_name => params[:last_name], :books => { :title => params[:book_name] } }, :include => :books)</code></pre>
<p>If we were writing this as an advanced search and wanted the parameters to be optional, we would break it out like this:</p>
<pre>
<code>conditions = {}
conditions[:first_name] = params[:first_name] unless params[:first_name].blank?
conditions[:last_name] = params[:last_name] unless params[:last_name].blank?
conditions[:books] = {:title => params[:book_name]} unless params[:book_name].blank?

@authors = Author.find(:conditions => conditions, :include => :books)
</code></pre>
<p>Simple!</p>
]]></content:encoded>
			<wfw:commentRss>http://omgsean.com/2009/02/targetting-associated-tables-in-an-activerecord-conditions-hash/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
