<?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>Scott Rutherford &#187; ruby</title>
	<atom:link href="http://blog.thatsuseful.com/tag/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.thatsuseful.com</link>
	<description>Life on and off the Rails</description>
	<lastBuildDate>Wed, 21 Jul 2010 16:35:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Ruby Time Functions Rock!!</title>
		<link>http://blog.thatsuseful.com/2007/02/04/ruby-time-functions-rock/</link>
		<comments>http://blog.thatsuseful.com/2007/02/04/ruby-time-functions-rock/#comments</comments>
		<pubDate>Sun, 04 Feb 2007 05:24:07 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://blog.caronsoftware.com/2007/11/25/ruby-time-functions-rock</guid>
		<description><![CDATA[I haven&#8217;t had much cause to play with the Time module in Ruby until today. I have used Time.now quite a bit, but not too much more than that. However, today I had to find the last 6 months names to label a graph and in a short period of time I had come up [...]]]></description>
			<content:encoded><![CDATA[<p>I haven&#8217;t had much cause to play with the Time module in Ruby until today. I have used Time.now quite a bit, but not too much more than that. However, today I had to find the last 6 months names to label a graph and in a short period of time I had come up with this:</p>
<pre>
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
labels = []
0.upto(5) do |x|
  labels.unshift(months[Time.now.months_ago(x).month-1])
end
</pre>
<p>Which I think is pretty neat, especially remembering what a pain it was in Perl last time I had to do it&#8230;&#8230;..</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.thatsuseful.com/2007/02/04/ruby-time-functions-rock/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ajax Scaffold Plugin &amp; Thoughts on Search</title>
		<link>http://blog.thatsuseful.com/2006/07/16/ajax-scaffold-plugin/</link>
		<comments>http://blog.thatsuseful.com/2006/07/16/ajax-scaffold-plugin/#comments</comments>
		<pubDate>Sun, 16 Jul 2006 09:53:43 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[AjaxScaffold]]></category>
		<category><![CDATA[Home]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://blog.caronsoftware.com/2007/11/25/ajax-scaffold-plugin</guid>
		<description><![CDATA[So Richard White caught up with me a couple of days ago through Technorati and we had a chat about the development of his Ajax Scaffolding as a Rails Plugin. We have agreed to work together on this (which is great) and develop the generator and the plugin in sync (As he also notes in [...]]]></description>
			<content:encoded><![CDATA[<p>So Richard White caught up with me a couple of days ago through <a href="http://www.technorati.com">Technorati</a> and we had a chat about the development of his Ajax Scaffolding as a Rails Plugin. We have agreed to work together on this (which is great) and develop the generator and the plugin in sync (As he also notes in his (kind) comments on the <a href="http://www.height1percent.com/articles/2006/07/14/ajaxscaffold-3-1-3-released">3.1.3 release</a> of the generator).</p>
<p>Hopefully the first release of the plugin should not to be too far away and will add a little functionality to the existing code.</p>
<p>            <span id="more-7"></span></p>
<p>One of the things I hope we can develop is a nice search interface to the table. I had to do this with the perl <a href="http://catalystframework.org">Catalyst Framework</a> earlier this year and I think the general approach could work quite well.</p>
<p>The approach I took was to define some (3 in fact) search tags which inherited from the basic html tags. So instead of just a &#8220;textfield&#8221; I had a &#8220;like_textfield&#8221;, or a &#8220;comparator_textfield&#8221;. This allowed me to easily add search functionality for each field in a model. This provides an exceptional comprehensive search system.</p>
<p>To clarify what I mean it is probably easiest to look at the sql mappings the tags produced:</p>
<ol>
<li>&#8220;comparator_textfield&#8221; &#8211; used for numerical values, comprises two fields, one a select containing &#8221;&lt;&#8221;, &#8221;&gt;&#8221; and &#8221;=&#8221; and a second for the value. So selecting &#8221;&gt;&#8221; and entering &#8220;2&#8221; in the field would translate to conditions such as &#8220;where x &lt; 2&#8221;</li>
</ol>
<ol>
<li>&#8220;like_textfield&#8221; &#8211; for full text search, comprises single textfield with a hidden &#8220;like&#8221; modifier field. So entering &#8220;scott rutherford&#8221; into the search would give &#8220;where x like &#8216;<span>scott</span>&#8221; or x like &#8216;<span>rutherford</span>&#8217;&#8221;</li>
</ol>
<ol>
<li>&#8216;comparator_datefield&#8217; &#8211; this was used for searching on dates, so like the numerical case this comprised 2 fields. The first held the modifiers &#8220;before&#8221;, &#8220;on&#8221;, &#8220;after&#8221; and the second drop downs to define the required date. This leads to sql like &#8220;where 20060506 &lt; date&#8221;, etc.</li>
</ol>
<p>Rails lends itself very nicely to this approach with the concept of helpers being fundamental to the framework. I feel it would be pretty easy to create helpers for these new search fields and then simply generate a form for a model on the fly as I did (using Richard&#8217;s existing helper code) with the scaffold plugin. The <strong>interesting</strong> bit comes in translating all of this into conditions for ActiveRecord, then storing it for the paging and sorting.</p>
<p>The easiest way to achieve this search persistence I feel is to just use the session object to store the current search, in fact that is the method I used previously and it seemed to work out.</p>
<p>Putting all that together would certainly lead to a radically different search to the &#8220;Live&#8221; search boxes that are all the rage currently, but my experience of working with tabulated data is that a simple text search is not enough.</p>
<p>At the moment I am beginning to think that this could be a plugin in its own right really and that if it is designed with AjaxScaffold in mind that then the search could potentially be made pluggable. Also of course that would mean you could just generate search forms for standard tables as well as Ajax ones (if that is for some strange reason you didn&#8217;t want your tables to look really cool&#8230;..).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.thatsuseful.com/2006/07/16/ajax-scaffold-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
