<?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>SmartLogic Solutions Blog &#187; Scott Davis</title>
	<atom:link href="http://blog.smartlogicsolutions.com/category/scott-davis/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.smartlogicsolutions.com</link>
	<description>News and updates from the people at SmartLogic Solutions</description>
	<lastBuildDate>Tue, 30 Nov 2010 21:39:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Facebox With Prototype</title>
		<link>http://blog.smartlogicsolutions.com/2008/10/14/facebox-with-prototype/</link>
		<comments>http://blog.smartlogicsolutions.com/2008/10/14/facebox-with-prototype/#comments</comments>
		<pubDate>Tue, 14 Oct 2008 18:58:55 +0000</pubDate>
		<dc:creator>Scott Davis</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Scott Davis]]></category>
		<category><![CDATA[facebox]]></category>
		<category><![CDATA[modal]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[window]]></category>

		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=316</guid>
		<description><![CDATA[After many failed attempts of trying to find a modal window that worked like facebox and used prototype, I gave up and started to write one from scratch. In the process I found the first port made by Phil Burrows. It wasn&#8217;t perfect but it was enough for me to build off of so with [...]]]></description>
			<content:encoded><![CDATA[<p>After many failed attempts of trying to find a modal window that worked like facebox and used prototype, I gave up and started to write one from scratch.  In the process I found the <a href="http://blog.philburrows.com">first port</a> made by <a href="http://blog.philburrows.com">Phil Burrows</a>. It wasn&#8217;t perfect but it was enough for me to build off of so with a few tweaks I was able to allow window resizing and let the box center itself.  You can view the changes on my <a href="http://github.com/jetviper21/prototype-facebox/tree/master/">github</a>.</p>
<p>Screenshot:<br />
<div id="attachment_317" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.smartlogicsolutions.com/wp-content/uploads/2008/10/picture-10.png"><img src="http://blog.smartlogicsolutions.com/wp-content/uploads/2008/10/picture-10-300x172.png" alt="My Version of Facebox in our timetracker application" title="Facebox" width="300" height="172" class="size-medium wp-image-317" /></a><p class="wp-caption-text">My Version of Facebox in our timetracker application</p></div></p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2008/11/12/watch-multiple-logs-in-a-single-terminal/" rel="bookmark" class="crp_title">Watch Multiple Logs in a Single Terminal</a></li><li><a href="http://blog.smartlogicsolutions.com/2009/05/05/smartlogic-wants-to-clean-up-twitter-introduces-shouldirtcom/" rel="bookmark" class="crp_title">SmartLogic Wants to Clean Up Twitter, Introduces ShouldIRT.com</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/08/21/getting-subclipse-to-work-in-gandymede-eclipse-34/" rel="bookmark" class="crp_title">Getting Subclipse to Work in Gandymede (Eclipse 3.4)</a></li><li><a href="http://blog.smartlogicsolutions.com/2009/11/24/rack-rewrite-google-analytics-makes-site-transitions-seamless/" rel="bookmark" class="crp_title">Rack::Rewrite + Google Analytics Makes Site Transitions Seamless</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/05/22/spotcrime-iphone-application-gets-techcrunched/" rel="bookmark" class="crp_title">SpotCrime iPhone Application gets TechCrunched</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.smartlogicsolutions.com/2008/10/14/facebox-with-prototype/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Making WillPaginate and Rails to_xml play nice with ActiveResource</title>
		<link>http://blog.smartlogicsolutions.com/2008/10/10/making-willpaginate-and-rails-to_xml-play-nice-with-activeresource/</link>
		<comments>http://blog.smartlogicsolutions.com/2008/10/10/making-willpaginate-and-rails-to_xml-play-nice-with-activeresource/#comments</comments>
		<pubDate>Fri, 10 Oct 2008 19:48:57 +0000</pubDate>
		<dc:creator>Scott Davis</dc:creator>
				<category><![CDATA[ActiveRecord]]></category>
		<category><![CDATA[AIR]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Scott Davis]]></category>
		<category><![CDATA[Serialization]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[Rails Will_Paginate to_xml ActiveResource]]></category>

		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=305</guid>
		<description><![CDATA[We are currently working on a project that involves Flex and active resource + will_paginate and we needed to be able to paginate the xml transactions easily. Unfortunately, will_paginate and to_xml don&#8217;t play nicely when it comes to adding the current_page, total_pages, and page attributes to the xml. After many failed attempts I went looking around github [...]]]></description>
			<content:encoded><![CDATA[<p>We are currently working on a project that involves Flex and active resource + will_paginate and we needed to be able to paginate the xml transactions easily. Unfortunately, will_paginate and to_xml don&#8217;t play nicely when it comes to adding the current_page, total_pages, and page attributes to the xml. After many failed attempts I went looking around <a href="http://github.com">github</a> and found in a few <a href="http://github.com/agile/will_paginate/tree/master">forks</a> of <a href="http://github.com/mislav/will_paginate/tree/master/">will paginate</a> that some people had solved this problem but, I didn&#8217;t want to install another version of the gem to risk breaking other apps on the server so I did it the rails way!</p>
<p>I started by creating a module that opens up the will_paginate <a href="http://github.com/mislav/will_paginate/tree/master/lib/will_paginate/collection.rb">collection</a> class and includes ActiveResource and alias method chain the to_xml method to include these values. Example code below.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#enviroment.rb</span>
...
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'to_xml_extensions'</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#lib/to_xml_extensions.rb</span>
<span style="color:#9966CC; font-weight:bold;">module</span> WillPaginateHelpers
  <span style="color:#9966CC; font-weight:bold;">include</span> <span style="color:#6666ff; font-weight:bold;">ActiveSupport::CoreExtensions</span>::<span style="color:#CC0066; font-weight:bold;">Array</span>::Conversions
  <span style="color:#9966CC; font-weight:bold;">def</span> to_xml_with_collection_type<span style="color:#006600; font-weight:bold;">&#40;</span>options = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        serializeable_collection.<span style="color:#9900CC;">to_xml_without_collection_type</span><span style="color:#006600; font-weight:bold;">&#40;</span>options<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>xml<span style="color:#006600; font-weight:bold;">|</span>
          xml.<span style="color:#9900CC;">tag</span>!<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:current_page</span>, <span style="color:#006600; font-weight:bold;">&#123;</span>:type <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveSupport::CoreExtensions</span>::<span style="color:#CC00FF; font-weight:bold;">Hash</span>::<span style="color:#6666ff; font-weight:bold;">Conversions::XML_TYPE_NAMES</span><span style="color:#006600; font-weight:bold;">&#91;</span>current_page.<span style="color:#9966CC; font-weight:bold;">class</span>.<span style="color:#9900CC;">name</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, current_page<span style="color:#006600; font-weight:bold;">&#41;</span>
          xml.<span style="color:#9900CC;">tag</span>!<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:per_page</span>, <span style="color:#006600; font-weight:bold;">&#123;</span>:type <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveSupport::CoreExtensions</span>::<span style="color:#CC00FF; font-weight:bold;">Hash</span>::<span style="color:#6666ff; font-weight:bold;">Conversions::XML_TYPE_NAMES</span><span style="color:#006600; font-weight:bold;">&#91;</span>per_page.<span style="color:#9966CC; font-weight:bold;">class</span>.<span style="color:#9900CC;">name</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, per_page<span style="color:#006600; font-weight:bold;">&#41;</span>
          xml.<span style="color:#9900CC;">tag</span>!<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:total_entries</span>, <span style="color:#006600; font-weight:bold;">&#123;</span>:type <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveSupport::CoreExtensions</span>::<span style="color:#CC00FF; font-weight:bold;">Hash</span>::<span style="color:#6666ff; font-weight:bold;">Conversions::XML_TYPE_NAMES</span><span style="color:#006600; font-weight:bold;">&#91;</span>total_entries.<span style="color:#9966CC; font-weight:bold;">class</span>.<span style="color:#9900CC;">name</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, total_entries<span style="color:#006600; font-weight:bold;">&#41;</span>
        <span style="color:#9966CC; font-weight:bold;">end</span>.<span style="color:#CC0066; font-weight:bold;">sub</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">%</span><span style="color:#006600; font-weight:bold;">&#123;</span>type=<span style="color:#996600;">&quot;array&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#006600; font-weight:bold;">%</span><span style="color:#006600; font-weight:bold;">&#123;</span>type=<span style="color:#996600;">&quot;collection&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
      alias_method_chain <span style="color:#ff3333; font-weight:bold;">:to_xml</span>, <span style="color:#ff3333; font-weight:bold;">:collection_type</span>
&nbsp;
      <span style="color:#9966CC; font-weight:bold;">def</span> serializeable_collection <span style="color:#008000; font-style:italic;">#:nodoc:</span>
        <span style="color:#008000; font-style:italic;"># Ugly hack because to_xml will not yield the XML Builder object when empty?</span>
        empty? ? returning<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">clone</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>c<span style="color:#006600; font-weight:bold;">|</span> c.<span style="color:#9900CC;">instance_eval</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>i<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#9966CC; font-weight:bold;">def</span> empty?; <span style="color:#0000FF; font-weight:bold;">false</span>; <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#006600; font-weight:bold;">&#125;</span> : <span style="color:#0000FF; font-weight:bold;">self</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#6666ff; font-weight:bold;">WillPaginate::Collection</span>.<span style="color:#9900CC;">send</span><span style="color:#006600; font-weight:bold;">&#40;</span>:<span style="color:#9966CC; font-weight:bold;">include</span>, WillPaginateHelpers<span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>This now gives me the proper xml when I call to_xml</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;time-cards</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;collection&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;current_page</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;integer&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/current_page<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;per_page</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;integer&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>25<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/per_page<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;total_entries</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;integer&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>108<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/total_entries<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;time_card<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;approved</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;boolean&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>false<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/approved<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;billable</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;boolean&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>false<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/billable<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;created_at</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;datetime&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>2008-10-10T14:04:13-04:00<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/created_at<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;date</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;datetime&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>2008-10-10T14:04:13-04:00<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/date<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;has_been_billed</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;boolean&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>false<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/has_been_billed<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;has_been_paid</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;boolean&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/has_been_paid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;hours</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;float&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>2.0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/hours<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;id</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;integer&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>98<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;is_overtime</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;boolean&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>false<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/is_overtime<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;task_id</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;integer&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>6<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/task_id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;updated_at</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;datetime&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>2008-10-10T14:04:13-04:00<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/updated_at<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;user_id</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;integer&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/user_id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/time_card<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  ...
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/timecards<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2008/10/28/faking-a-will-paginate-collection-on-an-active-resource-model/" rel="bookmark" class="crp_title">Faking a Will Paginate Collection on an Active Resource model</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/06/13/ruby-on-rails-polymorphic-association-benchmarks/" rel="bookmark" class="crp_title">Ruby on Rails Polymorphic Association Benchmarks</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/07/01/microsoft-webdav-opens-document-as-read-only-when-using-railsdav/" rel="bookmark" class="crp_title">Microsoft WebDav opens document as Read-Only when using RailsDav</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/09/10/using-activerecords-to_xml-to-produce-custom-xml-including-deep-level-associations/" rel="bookmark" class="crp_title">Using ActiveRecord&#8217;s to_xml to produce custom xml including deep level associations</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/06/03/error-in-will_paginate-gem-running-rails-210/" rel="bookmark" class="crp_title">Error in will_paginate gem running Rails 2.1.0</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.smartlogicsolutions.com/2008/10/10/making-willpaginate-and-rails-to_xml-play-nice-with-activeresource/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Advanced Model Based searches in rails</title>
		<link>http://blog.smartlogicsolutions.com/2008/07/21/advanced-model-based-searches-in-rails/</link>
		<comments>http://blog.smartlogicsolutions.com/2008/07/21/advanced-model-based-searches-in-rails/#comments</comments>
		<pubDate>Mon, 21 Jul 2008 16:24:55 +0000</pubDate>
		<dc:creator>Scott Davis</dc:creator>
				<category><![CDATA[ActiveRecord]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Scott Davis]]></category>
		<category><![CDATA[Advanced Search]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=102</guid>
		<description><![CDATA[After watching a railscast episode on advanced searching I thought I would give it a try. So I came up with a slightly modified version that would handle my search. Model class ExportSearch &#160; def timecards find_cards end &#160; def users&#40;u&#41; @u = u end &#160; def projects&#40;p&#41; @p = p end &#160; def tasks&#40;t&#41; [...]]]></description>
			<content:encoded><![CDATA[<p>After watching a <a href="http://railscasts.com/episodes/111" target="_blank">railscast episode</a> on advanced searching I thought I would give it a try.  So I came up with a slightly modified version that would handle my search.</p>
<h3>Model</h3>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> ExportSearch
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> timecards
    find_cards
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> users<span style="color:#006600; font-weight:bold;">&#40;</span>u<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0066ff; font-weight:bold;">@u</span> = u
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> projects<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0066; font-weight:bold;">p</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    @<span style="color:#CC0066; font-weight:bold;">p</span> = <span style="color:#CC0066; font-weight:bold;">p</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> tasks<span style="color:#006600; font-weight:bold;">&#40;</span>t<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0066ff; font-weight:bold;">@t</span> = t
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> dates<span style="color:#006600; font-weight:bold;">&#40;</span>date1, date2<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0066ff; font-weight:bold;">@d1</span> = date1
    <span style="color:#0066ff; font-weight:bold;">@d2</span> = date2
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> clients<span style="color:#006600; font-weight:bold;">&#40;</span>c<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0066ff; font-weight:bold;">@c</span> = c
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
private
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> find_cards
    TimeCard.<span style="color:#9900CC;">find</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:all</span>, <span style="color:#ff3333; font-weight:bold;">:conditions</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> conditions, :<span style="color:#9966CC; font-weight:bold;">include</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>:task <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:project</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#ff3333; font-weight:bold;">:order</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:date</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> projects_conditions
    <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;tasks.project_id IN (?)&quot;</span>, @<span style="color:#CC0066; font-weight:bold;">p</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#9966CC; font-weight:bold;">unless</span> @<span style="color:#CC0066; font-weight:bold;">p</span>.<span style="color:#9900CC;">blank</span>?
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> client_conditions
    <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;projects.client_id IN (?)&quot;</span>, <span style="color:#0066ff; font-weight:bold;">@c</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#9966CC; font-weight:bold;">unless</span> <span style="color:#0066ff; font-weight:bold;">@c</span>.<span style="color:#9900CC;">blank</span>?
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> date_conditions
    <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;date BETWEEN ? AND ?&quot;</span>, <span style="color:#0066ff; font-weight:bold;">@d1</span>, <span style="color:#0066ff; font-weight:bold;">@d2</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#9966CC; font-weight:bold;">unless</span> <span style="color:#006600; font-weight:bold;">&#40;</span>@d1.<span style="color:#9900CC;">blank</span>? <span style="color:#006600; font-weight:bold;">||</span> <span style="color:#0066ff; font-weight:bold;">@d2</span>.<span style="color:#9900CC;">blank</span>?<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> task_conditions
    <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;task_id IN (?)&quot;</span>, <span style="color:#0066ff; font-weight:bold;">@t</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#9966CC; font-weight:bold;">unless</span> <span style="color:#0066ff; font-weight:bold;">@t</span>.<span style="color:#9900CC;">blank</span>?
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> users_conditions
    <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;user_id IN (?)&quot;</span>, <span style="color:#0066ff; font-weight:bold;">@u</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#9966CC; font-weight:bold;">unless</span> <span style="color:#0066ff; font-weight:bold;">@u</span>.<span style="color:#9900CC;">blank</span>?
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> conditions
    <span style="color:#006600; font-weight:bold;">&#91;</span>conditions_clauses.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">' AND '</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#006600; font-weight:bold;">*</span>conditions_options<span style="color:#006600; font-weight:bold;">&#93;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> conditions_clauses
    conditions_parts.<span style="color:#9900CC;">map</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>condition<span style="color:#006600; font-weight:bold;">|</span> condition.<span style="color:#9900CC;">first</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> conditions_options
    conditions_parts.<span style="color:#9900CC;">map</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>condition<span style="color:#006600; font-weight:bold;">|</span> condition<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span>..<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">flatten</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> conditions_parts
    private_methods<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">grep</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>_conditions$<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">map</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>m<span style="color:#006600; font-weight:bold;">|</span> send<span style="color:#006600; font-weight:bold;">&#40;</span>m<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">compact</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<h3>Controller</h3>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">    search = ExportSearch.<span style="color:#9900CC;">new</span>
    search.<span style="color:#9900CC;">users</span><span style="color:#006600; font-weight:bold;">&#40;</span>params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:export</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:users</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">','</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">unless</span> params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:export</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:users</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">blank</span>?
    search.<span style="color:#9900CC;">tasks</span><span style="color:#006600; font-weight:bold;">&#40;</span>params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:export</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:tasks</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">','</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">unless</span> params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:export</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:tasks</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">blank</span>?
    search.<span style="color:#9900CC;">projects</span><span style="color:#006600; font-weight:bold;">&#40;</span>params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:export</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:projects</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">','</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">unless</span> params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:export</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:projects</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">blank</span>?
    search.<span style="color:#9900CC;">dates</span><span style="color:#006600; font-weight:bold;">&#40;</span>start_date, end_date<span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    <span style="color:#0066ff; font-weight:bold;">@time_cards</span> = search.<span style="color:#9900CC;">timecards</span></pre></div></div>

<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2009/10/23/dry-up-your-controllers-with-find_or_redirect/" rel="bookmark" class="crp_title">DRY up your Controllers with find_or_redirect</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/07/10/merging-a-has_many-relationship-into-one-instance/" rel="bookmark" class="crp_title">Merging a :has_many relationship into one instance</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/06/11/multithreading-in-ruby-on-rails/" rel="bookmark" class="crp_title">Multithreading in Ruby on Rails</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/10/28/faking-a-will-paginate-collection-on-an-active-resource-model/" rel="bookmark" class="crp_title">Faking a Will Paginate Collection on an Active Resource model</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/06/05/mapresources-and-custom-nested-routes/" rel="bookmark" class="crp_title">map.resources and custom nested routes</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.smartlogicsolutions.com/2008/07/21/advanced-model-based-searches-in-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>map.resources and custom nested routes</title>
		<link>http://blog.smartlogicsolutions.com/2008/06/05/mapresources-and-custom-nested-routes/</link>
		<comments>http://blog.smartlogicsolutions.com/2008/06/05/mapresources-and-custom-nested-routes/#comments</comments>
		<pubDate>Thu, 05 Jun 2008 19:25:21 +0000</pubDate>
		<dc:creator>Scott Davis</dc:creator>
				<category><![CDATA[Routing]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Scott Davis]]></category>

		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/2008/06/05/mapresources-and-custom-nested-routes/</guid>
		<description><![CDATA[I encountered an error in rails trying to create a nested route in rails 2.x map.import_time_cards 'users/:user_id/time_cards/import', :controller => 'time_cards', :action => 'import' Wasn&#8217;t setting up a route for users because this route was being setup automatically and overwritten by: map.resources :users, :has_many => [:notes, :addresses, :expenses, :time_cards] , :collection => [:login, :logout, :disable, :enable] [...]]]></description>
			<content:encoded><![CDATA[<p>I encountered an error in rails trying to create a nested route in rails 2.x<br />
<code><br />
map.import_time_cards 'users/:user_id/time_cards/import',<br />
  :controller => 'time_cards',<br />
  :action => 'import'<br />
</code><br />
Wasn&#8217;t setting up a route for users because this route was being setup automatically and overwritten by:<br />
<code><br />
map.resources :users,<br />
  :has_many => [:notes, :addresses, :expenses, :time_cards] ,<br />
  :collection => [:login, :logout, :disable, :enable]<br />
</code><br />
So after digging around on the rails <a href="http://api.rubyonrails.org">api</a> I discovered that map.resources takes a block so my solution to this problem was :<br />
<code><br />
map.resources(:users,<br />
  :has_many => [:notes, :addresses, :expenses] ,<br />
  :collection => [:login, :logout, :disable, :enable]) do |user|<br />
    user.resources :time_cards, :collection => [:import]<br />
  end<br />
</code><br />
By using a block this tells rails to include route to &#8216;users/1/time_cards/import&#8217; instead of appending import as the id for the show route.</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2008/07/21/advanced-model-based-searches-in-rails/" rel="bookmark" class="crp_title">Advanced Model Based searches in rails</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/05/22/spotcrime-iphone-application-gets-techcrunched/" rel="bookmark" class="crp_title">SpotCrime iPhone Application gets TechCrunched</a></li><li><a href="http://blog.smartlogicsolutions.com/2009/05/26/including-external-rake-files-in-your-projects-rakefile-keep-your-rake-tasks-organized/" rel="bookmark" class="crp_title">Including external .rake files in your project&#8217;s Rakefile &#8212; keep your rake tasks organized!</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/05/16/flash-player-10-astro-flex-sdk-compile/" rel="bookmark" class="crp_title">Flash Player 10 (&#8220;Astro&#8221;) Prerelease and Flex SDK Build Available to Compile Flash Player 10 Content</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/10/28/faking-a-will-paginate-collection-on-an-active-resource-model/" rel="bookmark" class="crp_title">Faking a Will Paginate Collection on an Active Resource model</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.smartlogicsolutions.com/2008/06/05/mapresources-and-custom-nested-routes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SLS Welcomes Scott Davis to the Team</title>
		<link>http://blog.smartlogicsolutions.com/2007/05/07/sls-welcomes-scott-davis-to-the-team/</link>
		<comments>http://blog.smartlogicsolutions.com/2007/05/07/sls-welcomes-scott-davis-to-the-team/#comments</comments>
		<pubDate>Mon, 07 May 2007 23:21:04 +0000</pubDate>
		<dc:creator>Yair Flicker</dc:creator>
				<category><![CDATA[Company News]]></category>
		<category><![CDATA[New Hires]]></category>
		<category><![CDATA[Scott Davis]]></category>

		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/2007/05/07/sls-welcomes-scott-davis-to-the-team/</guid>
		<description><![CDATA[Welcome to Scott Davis! We&#8217;ve hired Scott as an intern for the summer and hopefully longer. Scott is a fast learner, highly motivated, has a positive attitude and should be a great addition to the company. Scott&#8217;s first assignment is to learn Ruby on Rails (RoR) so that he can assist us with creating web [...]]]></description>
			<content:encoded><![CDATA[<p>Welcome to <strong><a href="http://www.smartlogicsolutions.com/wiki/Scott_Davis">Scott Davis</a></strong>!  We&#8217;ve hired Scott as an intern for the summer and hopefully longer.  Scott is a fast learner, highly motivated, has a positive attitude and should be a great addition to the company.  Scott&#8217;s first assignment is to learn Ruby on Rails (RoR) so that he can assist us with creating web applications.  A few weeks before he started with us he had already bought up some RoR books and started learning the language/framework on his own &#8211; nice!</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2007/05/11/we-moved-to-a-bigger-office/" rel="bookmark" class="crp_title">We Moved to a Bigger Office</a></li><li><a href="http://blog.smartlogicsolutions.com/2007/05/10/happy-birthday-smartlogic-solutions/" rel="bookmark" class="crp_title">Happy Birthday SmartLogic Solutions!</a></li><li><a href="http://blog.smartlogicsolutions.com/2007/05/16/sls-welcomes-joseph-jakuta/" rel="bookmark" class="crp_title">SLS Welcomes Joseph Jakuta</a></li><li><a href="http://blog.smartlogicsolutions.com/2007/03/01/introducing-smartlogic-solutions-blog/" rel="bookmark" class="crp_title">Introducing the SmartLogic Solutions Blog</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/08/30/nicks-highlights-from-lone-star-ruby-conf/" rel="bookmark" class="crp_title">Nick&#8217;s Highlights from Lone Star Ruby Conf</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.smartlogicsolutions.com/2007/05/07/sls-welcomes-scott-davis-to-the-team/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

