<?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>David Lowry &#187; rails</title>
	<atom:link href="http://davidlowry.co.uk/category/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://davidlowry.co.uk</link>
	<description>Setting out freelance with Web and AV Solutions</description>
	<lastBuildDate>Thu, 24 Jun 2010 13:16:28 +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>Site Launch — Tales of the Unexpected</title>
		<link>http://davidlowry.co.uk/site-launch-%e2%80%94-tales-of-the-unexpected/</link>
		<comments>http://davidlowry.co.uk/site-launch-%e2%80%94-tales-of-the-unexpected/#comments</comments>
		<pubDate>Mon, 26 Apr 2010 12:07:06 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[blog]]></category>
		<category><![CDATA[meaningful labor]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://davidlowry.co.uk/?p=333</guid>
		<description><![CDATA[Last week saw the launch of TOTU: Tales of the Unexpected, a Summer Madness and Exodus project. The site was developed by me with visual identity design by Connie &#038; Craig, the super-talented folks over at]]></description>
			<content:encoded><![CDATA[<p>Last week saw the launch of <a href="http://talesoftheunexpected.org/">TOTU: Tales of the Unexpected</a>, a Summer Madness and Exodus project. The site was developed by me with visual identity design by Connie &#038; Craig, the super-talented folks over at <a href="http://www.studiostereo.co.uk>Stereo</a>. Big kudos as well to Matt for his management of the project and JK for the Big Idea.</p>
<p>As well as creating the web portal, between us we split the responsibility for shooting and editing the video material, and if you know Stereo&#8217;s work you know they&#8217;ll come up with a <a href="http://www.youtube.com/v/lCYgQWLO8vY">beautiful end product</a>.</p>
<blockquote><p>&#8220;TOTU is an opportunity for everyday people to express a part of their lives, a snapshot of faith, or quite simply, an encounter of God &#8211; and that&#8217;s always worth talking about&#8221;
</p></blockquote>
<p>I hope you enjoy watching the videos and maybe feel inspired to <a href="http://talesoftheunexpected.org/share">share</a>.</p>
<p>So, <a href="http://talesoftheunexpected.org/">the site is now live</a>. Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://davidlowry.co.uk/site-launch-%e2%80%94-tales-of-the-unexpected/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby on Rails: Get some random records</title>
		<link>http://davidlowry.co.uk/ruby-on-rails-get-some-random-records/</link>
		<comments>http://davidlowry.co.uk/ruby-on-rails-get-some-random-records/#comments</comments>
		<pubDate>Mon, 30 Nov 2009 13:04:38 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[learning]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://davidlowry.co.uk/?p=293</guid>
		<description><![CDATA[EDIT AGAIN: Much better.. To get a &#8216;num_reqd&#8217; array of random objects, you can use something like this. named_scope :large, :conditions => ['image_file_name IS NOT ?', nil] named_scope :small, :conditions => ['small_image_file_name IS NOT ?', nil] def self.get(num_reqd,features_arr=[],size="large") if size=="small" &#8230; <a href="http://davidlowry.co.uk/ruby-on-rails-get-some-random-records/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>EDIT AGAIN: Much better..</p>
<p>To get a &#8216;num_reqd&#8217; array of random objects, you can use something like this.</p>
<pre><code>  named_scope :large, :conditions => ['image_file_name IS NOT ?', nil]
  named_scope :small, :conditions => ['small_image_file_name IS NOT ?', nil] 

  def self.get(num_reqd,features_arr=[],size="large")
    if size=="small"
      collection = Feature.small
    elsif size=="large"
      collection = Feature.large
    end

    return collection if collection.size <= num_reqd

    # num_reqd.times{feature=self.random(collection); features_arr.push(feature) unless features_arr.include?(feature)}
    features_arr = collection.find(:all, :limit => num_reqd, <img src='http://davidlowry.co.uk/wordpress/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> rder => 'rand()')

    if features_arr.size < num_reqd
      return Feature.get(num_reqd, features_arr, size)
    else
      return features_arr
    end
  end</code></pre>
<p>EDIT: It's much cleaner and easier to use something in the form below, though the following is probably useful in some cases and is possibly interesting as a code snippet.<br />
<code>
<pre>
User.find(:all, <img src='http://davidlowry.co.uk/wordpress/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> rder => 'rand()')
</pre>
<p></code><br />
---- end edit.</p>
<p>Working from a baseline of the code found <a href="http://almosteffortless.com/2007/12/04/random-records-in-rails/">here at almosteffortless.com</a> I've extended a 'random record grabber' to get a specific number of unique records from a Rails data table.</p>
<p>Basically - the random method makes a database call to get the ids of a table, and sends back a random entry. <code>self.get</code> is a recursive method which provides a 'total number required' and a base array to start from (if you wish to specify entries to appear in the otherwise 'random' list). First year computer science should help get your head around the rest!</p>
<p><code>
<pre>
def self.random
    ids = connection.select_all("SELECT id FROM features")
    find(ids[rand(ids.length)]["id"].to_i) unless ids.blank?
  end

  def self.get(num_reqd,features_arr=[])
    num_reqd.times{feature=self.random; features_arr.push(feature) unless features_arr.include?(feature)}

    if features_arr.size < num_reqd
      return Feature.get(num_reqd, features_arr)
    else
      return features_arr
    end
  end</pre>
<p></code></p>
<p>Be aware, there is more efficiency to be found in the database call (i.e. it should be cached). Also, you'll want to be sure there are at least 'num_reqd' items in the database.</p>
]]></content:encoded>
			<wfw:commentRss>http://davidlowry.co.uk/ruby-on-rails-get-some-random-records/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple Thinking Sphinx on Dreamhost</title>
		<link>http://davidlowry.co.uk/simple-thinking-sphinx-on-dreamhost/</link>
		<comments>http://davidlowry.co.uk/simple-thinking-sphinx-on-dreamhost/#comments</comments>
		<pubDate>Wed, 28 Oct 2009 13:10:16 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[learning]]></category>
		<category><![CDATA[meaningful labor]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[dreamhost]]></category>
		<category><![CDATA[railscasts]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[sphinx]]></category>
		<category><![CDATA[thinking sphinx]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://davidlowry.co.uk/?p=279</guid>
		<description><![CDATA[*** Please note &#8211; this will probably not work (at all) (for more than a day of light use) without Cron use. And isn&#8217;t at all authorised by Dreamhost!! *** For a recent client project I&#8217;ve used a Dreamhost unlimited &#8230; <a href="http://davidlowry.co.uk/simple-thinking-sphinx-on-dreamhost/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>*** Please note &#8211; this will probably not work (at all) (for more than a day of light use) without Cron use. And isn&#8217;t at all authorised by Dreamhost!! *** </p>
<p>For a recent client project I&#8217;ve used a Dreamhost unlimited account, which for value compared with the resources available and the fact that you don&#8217;t have to do any building or setting up of the server environment makes it an easy win for a site that&#8217;s not going to have a huge amount of traffic or a large amount of processing.</p>
<p>Post-launch I got to work putting together a basic search engine and here&#8217;s a quick run through of the steps it took to get a very simple Sphinx instance working on Dreamhost, and a few hurdles thrown in the way by various googled articles.</p>
<h3>Development Environment</h3>
<p>Using the <a href="http://freelancing-gods.com/posts/a_concise_guide_to_using_thinking_sphinx">guide from FG</a> install Sphinx locally:</p>
<pre><code>curl -O http://sphinxsearch.com/downloads/sphinx-0.9.8-rc2.tar.gz
tar zxvf sphinx-0.9.8-rc2.tar.gz
cd sphinx-0.9.8-rc2
./configure
make
sudo make install</code></pre>
<p>then install the TS plugin into your application</p>
<pre><code>script/plugin install git://github.com/freelancing-god/thinking-sphinx.git
</code></pre>
<p>Any problems with that, check out the <a href="http://freelancing-gods.com/posts/a_concise_guide_to_using_thinking_sphinx">FG page</a> linked.</p>
<h3>Getting a basic search going</h3>
<p>Following tutorials such as the <a href="http://railscasts.com/episodes/120-thinking-sphinx">Sphinx Railscast</a> will get you there pretty quick.</p>
<p>In your searchable model you need to define an index</p>
<pre><code>
class Page < ActiveRecord::Base
  define_index do
    indexes :title
    indexes :long
    indexes :short
  end ...</code></pre>
<p>Run the indexer and start the Sphinx instance:</p>
<pre><code>
rake thinking_sphinx:index
rake thinking_sphinx:start</code></pre>
<p>After this you'll be able to search on your object. So using script/console</p>
<pre><code>@searched_pages = Page.search("query")</code></pre>
<p>will return what you're looking for!</p>
<h3>Setting up Dreamhost</h3>
<p>First things first you need to install Sphinx in your local area, as posted <a href="http://hughevans.net/2009/03/10/thinking-sphinx-dreamhost">by Hugh Evans</a>:</p>
<pre><code>cd ~/
mkdir -p local
wget http://sphinxsearch.com/downloads/sphinx-0.9.8.1.tar.gz
tar -xzf sphinx-0.9.8.1.tar.gz
cd sphinx-0.9.8.1/
./configure --prefix=$HOME/local/ --exec-prefix=$HOME/local/
make
make install</code></pre>
<p>then set up the PATHs</p>
<pre><code>echo "export PATH=\"$PATH:~/local/bin\"" >> ~/.bash_profile
source ~/.bash_profile</code></pre>
<p>You can choose to set up a CRON task at this point too, but I'm not going into that.</p>
<p>Also at this point in the there's talk of using Sphinx being anti TOS in DH's eyes... but we'll see does the process get killed or not!</p>
<h3>Configuring Sphinx for DH</h3>
<p>Create a file called sphinx.yml in the RAILS_ROOT/config/ folder.</p>
<p>Because Dreamhost uses an externally referenced MySQL server instead of localhost you need to set up the sql_* parameters:</p>
<pre><code>
  sql_host: "mysql.YOURDOMAIN"
  sql_port: 3306
  sql_user: "USER"
  sql_password: "PASSWORD"
  sql_database: "DATABASE"
</code></pre>
<p>And because you installed Sphinx in your local area:</p>
<pre><code>
  bin_path: '/home/YOURUSERNAME/local/bin'
</code></pre>
<p>Finally, after setting whatever memory/fine tuning settings you wish/require set up the locations for the Sphinx files:</p>
<pre><code>
  config_file: "/home/YOURUSERNAME/DOMAIN.co.uk/shared/production.sphinx.conf"
  searchd_log_file: "/home/YOURUSERNAME/DOMAIN.co.uk/shared/log/searchd.log"
  query_log_file: "/home/YOURUSERNAME/DOMAIN.co.uk/shared/log/searchd.query.log"
  pid_file: "/home/YOURUSERNAME/DOMAIN.co.uk/shared/log/searchd.production.pid"
  searchd_file_path: "/home/YOURUSERNAME/DOMAIN.co.uk/shared/db/sphinx"
</code></pre>
<p>That should be you ready to start deploying.</p>
<h3>Deploying</h3>
<p>Using Git + Capistrano for deployment (and Passenger for the http server) my deploy.rb's namespace area looks like this:</p>
<pre><code>
namespace :deploy do
  task :restart do
    after_symlink
    restart_sphinx
    run "touch #{deploy_to}/current/tmp/restart.txt"
  end

  task :start do
    # nothing  (this avoids the 'spin' script issue)
  end

  desc "Re-establish symlinks"
  task :after_symlink do
    run <<-CMD
      rm -fr #{release_path}/db/sphinx &#038;&#038;
      ln -nfs #{shared_path}/db/sphinx #{release_path}/db/sphinx
    CMD
  end

  desc "Stop the sphinx server"
  task :stop_sphinx , :roles => :app do
    run "cd #{current_path} &#038;&#038; rake thinking_sphinx:stop RAILS_ENV=production"
  end

  desc "Start the sphinx server"
  task :start_sphinx, :roles => :app do
    run "cd #{current_path} &#038;&#038; rake thinking_sphinx:configure RAILS_ENV=production &#038;&#038; rake thinking_sphinx:index RAILS_ENV=production &#038;&#038; rake thinking_sphinx:start RAILS_ENV=production"
  end

  desc "Restart the sphinx server"
  task :restart_sphinx, :roles => :app do
    stop_sphinx
    start_sphinx
  end

end
</code></pre>
<p>There's probably a neater way to do this, but basically this makes sure Sphinx's indexes and conf files live in the shared deployment folder.</p>
<p>I recommend you try all this in a staging area first, obviously... and you can use Dreamhost's control panel to set up a staging subdomain with a new database in whatever fashion you prefer.</p>
<p>Any problems with this script flag them up, please! This is as much for my future reference as you googlies out there.</p>
]]></content:encoded>
			<wfw:commentRss>http://davidlowry.co.uk/simple-thinking-sphinx-on-dreamhost/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails / LAMP / WordPress Setup Guide</title>
		<link>http://davidlowry.co.uk/rails-lamp-wordpress-setup-guide/</link>
		<comments>http://davidlowry.co.uk/rails-lamp-wordpress-setup-guide/#comments</comments>
		<pubDate>Thu, 07 May 2009 19:47:27 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[blog]]></category>
		<category><![CDATA[meaningful labor]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[environment]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[lamp]]></category>
		<category><![CDATA[setup]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://davidlowry.co.uk/rails-lamp-wordpress-setup-guide/</guid>
		<description><![CDATA[I&#8217;ve had huge amounts of pain getting WordPress set up locally over the last few weeks on my old machine and when it struck again with my new development environment it definitely time to write down the required steps to &#8230; <a href="http://davidlowry.co.uk/rails-lamp-wordpress-setup-guide/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve had huge amounts of pain getting WordPress set up locally over the last few weeks on my old machine and when it struck again with my new development environment it definitely time to write down the required steps to get a great LAMP/Rails setup prepared (for me)!</p>
<p>Leopard has PHP and Apache fairly up to date, and probably MySQL as well, but I decided to get MySQL up to scratch using the Universal Binary along with a few command line instructions available <a href="http://developer.apple.com/internet/opensource/osdb.html">here (guide and links to downloads)</a>.</p>
<p>I didn&#8217;t use this script myself, and at a year old it may have a few imperfections, but <a href="http://hivelogic.com/articles/view/ruby-rails-leopard">HiveLogic have a fairly well rounded Ruby/Rails install going on.</a></p>
<p>Finally, WordPress to go on your LAMP stack will be a lot less painful using <a href="http://www.tech-recipes.com/rx/2757/leopard_how_to_install_wordpress/">this guide for Tech Recipes</a>.</p>
<p>Any suggestions additions or replacements for this list? Drop a comment!</p>
]]></content:encoded>
			<wfw:commentRss>http://davidlowry.co.uk/rails-lamp-wordpress-setup-guide/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>It&#8217;s been quiet around here</title>
		<link>http://davidlowry.co.uk/its-been-quiet-around-here/</link>
		<comments>http://davidlowry.co.uk/its-been-quiet-around-here/#comments</comments>
		<pubDate>Thu, 07 May 2009 19:33:52 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[blog]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[busy!]]></category>
		<category><![CDATA[contrast.ie]]></category>
		<category><![CDATA[freelance]]></category>

		<guid isPermaLink="false">http://davidlowry.co.uk/?p=253</guid>
		<description><![CDATA[I have six draft posts in the wings waiting to be pushed out, works in progress related to technologies I&#8217;ve been working with lately for Contrast.ie Working on a still-hush-hush project with the lads best known for their rock star &#8230; <a href="http://davidlowry.co.uk/its-been-quiet-around-here/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.contrast.ie"><img src="http://davidlowry.co.uk/wordpress/wp-content/uploads/2009/05/geeky-irish-rockstars-300x163.png" alt="The Geeky Irish Rockstars" title="The Geeky Irish Rockstars" width="300" height="163" class="alignright size-medium wp-image-254" style="float: right; padding: 5px;" /></a> I have six draft posts in the wings waiting to be pushed out, works in progress related to technologies I&#8217;ve been working with lately for <a href="http://www.contrast.ie">Contrast.ie</a></p>
<p>Working on a still-hush-hush project with the lads best known for their rock star company photo and probably this week for their <a href="http://twitpic.com/4mktp ">choice of marketing</a> for <a href="http://www.getexceptional.com">Exceptional, the bug tracking tool for Rails (and more)</a> at Railsconf in Las Vegas</a>.</p>
<p>Part of the reason there&#8217;s been so little going on here is that I&#8217;ve been&#8230; well&#8230; rather busy. Trying to get client work done as well as freelancing with Contrast has been a bit of a struggle and I&#8217;ve just spent three days getting my brand new 24&#8243; iMac set up and running&#8230; a pain worth the endurance, though I&#8217;m fairly certain I now need a bigger desk!</p>
<p>So, some posts about Rails, HAML, Cucumber, and possibly a very very late review of FOWA Dublin which never quite got finished coming up in the next few weeks.</p>
]]></content:encoded>
			<wfw:commentRss>http://davidlowry.co.uk/its-been-quiet-around-here/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Git Pro Tips!</title>
		<link>http://davidlowry.co.uk/git-pro-tips/</link>
		<comments>http://davidlowry.co.uk/git-pro-tips/#comments</comments>
		<pubDate>Sun, 22 Feb 2009 17:51:10 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[blog]]></category>
		<category><![CDATA[meaningful labor]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[repository]]></category>

		<guid isPermaLink="false">http://davidlowry.co.uk/?p=230</guid>
		<description><![CDATA[Stumbled across this fella on Twitter today, noticed he worked at Slide (who make successful/annoying Facebook Apps). None the less (I joke) he writes a blog at http://www.unethicalblogger.com/ and has recently been writing a series of &#8216;ProTips&#8217; on using Git &#8230; <a href="http://davidlowry.co.uk/git-pro-tips/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Stumbled across this fella on Twitter today, noticed he worked at Slide (who make successful/annoying Facebook Apps). None the less (I joke) he writes a blog at <a href="http://www.unethicalblogger.com/">http://www.unethicalblogger.com/</a> and has recently been writing a series of &#8216;ProTips&#8217; on using Git Repos for his work colleagues.</p>
<p>I think it might prove useful: <a href="http://www.unethicalblogger.com/blog_categories/git">http://www.unethicalblogger.com/blog_categories/git</a> will be taking a read in my spare time.</p>
]]></content:encoded>
			<wfw:commentRss>http://davidlowry.co.uk/git-pro-tips/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby Uninitialized Constant Error (Mental Note)</title>
		<link>http://davidlowry.co.uk/ruby-uninitialized-constant-error-mental-note/</link>
		<comments>http://davidlowry.co.uk/ruby-uninitialized-constant-error-mental-note/#comments</comments>
		<pubDate>Mon, 14 Apr 2008 15:37:28 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[learning]]></category>
		<category><![CDATA[meaningful labor]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[script generate]]></category>
		<category><![CDATA[uninitialized constants]]></category>

		<guid isPermaLink="false">http://davidlowry.co.uk/?p=114</guid>
		<description><![CDATA[The reason I always get initialized constant errors occurring in Ruby is accidentally naming models the plural form of the database table name and not letting Rails automatically create the pluralisations. script/generate scaffold contact_skill contact_id:integer skill_id:integer description:string not script/generate scaffold &#8230; <a href="http://davidlowry.co.uk/ruby-uninitialized-constant-error-mental-note/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The reason I always get initialized constant errors occurring in Ruby is accidentally naming models the plural form of the database table name and not letting Rails automatically create the pluralisations.</p>
<p><code>script/generate scaffold contact_skill contact_id:integer skill_id:integer description:string </code><br />
not<br />
<code>script/generate scaffold contact_skills ... </code></p>
<p>(This reason is one I constantly forget, and Google never helps me. Now I will not forget)</p>
<p>&#8212;&#8211;</p>
<p>edit: I&#8217;ve had a LOAD of google hits from this search query in the last few days, if this helps you <em>or doesn&#8217;t</em> please leave a comment to make this article more complete.</p>
]]></content:encoded>
			<wfw:commentRss>http://davidlowry.co.uk/ruby-uninitialized-constant-error-mental-note/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
