<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/stylesheets/rss.css" type="text/css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>mehblog: Category Rails</title>
    <link>http://blog.pauldalton.co.uk/articles/category/rails</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>random mumblings</description>
    <item>
      <title>My take on the 7 reasons...</title>
      <description>&lt;p&gt;So the hottest topic in the rails community is seems is &lt;a href="http://www.oreillynet.com/ruby/blog/2007/09/7_reasons_i_switched_back_to_p_1.html"&gt;Derek Sivers&amp;#8217; blog post&lt;/a&gt; on why he switched from trying to reimplement his site in rails to php.&lt;/p&gt;


	&lt;p&gt;As someone who writes both rails and php for a living I feel that I have
a good perspective on the rails vs php thing.&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;m sure the arguments will continue for some time, but all I know is that I write &lt;strong&gt;much&lt;/strong&gt; better php since working with rails.&lt;/p&gt;


	&lt;p&gt;Right tool for the job and all that.&lt;/p&gt;</description>
      <pubDate>Thu, 27 Sep 2007 09:47:00 +0100</pubDate>
      <guid isPermaLink="false">urn:uuid:69d4958e-c601-4803-8b56-afdcc2e40f74</guid>
      <author>paul</author>
      <link>http://blog.pauldalton.co.uk/articles/2007/09/27/my-take-on-the-7-reasons</link>
      <category>PHP</category>
      <category>Rails</category>
      <category>Mumblings</category>
    </item>
    <item>
      <title>Upgrade to Typo 4</title>
      <description>&lt;p&gt;I have upgraded my blog to &lt;a href="http://typosphere.org/"&gt;Typo&lt;/a&gt; version 4 and it went mostly seamlessly.&lt;/p&gt;


	&lt;p&gt;The box that hosts this blog is running &lt;a href="http://www.plesk.com"&gt;plesk&lt;/a&gt; which wasn&amp;#8217;t a problem.&lt;/p&gt;


	&lt;p&gt;I tried just installing the new version of typo over the old 2.6 version and while this appeared to work it caused some problems, notably with the migrations.&lt;/p&gt;


	&lt;p&gt;In the end I deleted my old typo install and ran these commands:&lt;/p&gt;


	&lt;p&gt;This box is running &lt;a href="http://www.centos.org"&gt;Centos 4&lt;/a&gt; . I had sqlite installed but not the header files. These are required to get the sqlite gem files to install which are required by typo.&lt;/p&gt;


&lt;pre&gt;yum install sqlite-devel&lt;/pre&gt;

	&lt;p&gt;Install the typo gem:&lt;/p&gt;


&lt;pre&gt;gem install typo&lt;/pre&gt;

	&lt;p&gt;Install typo in my webroot:&lt;/p&gt;


&lt;pre&gt; typo install /var/www/PATH/httpdocs&lt;/pre&gt;

	&lt;p&gt;The next command should have changed the configuration from mongrel and sqlite to apache and mysql but it didn&amp;#8217;t work for me for some reason:&lt;/p&gt;


&lt;pre&gt;typo config /var/www/PATH/httpdocs web-server=external database=mysql&lt;/pre&gt;

	&lt;p&gt;I had to manually change the settings in database.yml and I also had to create a .htaccess file in the public folder to get fastcgi working.&lt;/p&gt;


	&lt;p&gt;Then &lt;pre&gt;rake migrate&lt;/pre&gt; to update the database tables.&lt;/p&gt;


	&lt;p&gt;I have moved the blog a few times over the last year or so and along the way various things got broken, so it is nice to have everything working again.&lt;/p&gt;</description>
      <pubDate>Wed, 26 Jul 2006 09:58:00 +0100</pubDate>
      <guid isPermaLink="false">urn:uuid:9d561e90-3cc5-4c8e-9e56-a9ae73963f2c</guid>
      <author>paul</author>
      <link>http://blog.pauldalton.co.uk/articles/2006/07/26/upgrade-to-typo-4</link>
      <category>General</category>
      <category>Rails</category>
    </item>
    <item>
      <title>[snippet] Cleaning up currency strings</title>
      <description>&lt;p&gt;I was working on some data that I needed to import into mysql for a new rails project I&amp;#8217;ve started.&lt;/p&gt;


	&lt;p&gt;Some of the fields are currency strings, eg &#163;4,000.00. Now initially I was tempted to just bung them into the table as varchars but there is a good chance that at some point down the line I&amp;#8217;m going to want to &amp;#8216;do maths&amp;#8217; with these numbers so I really had to convert them to floats.&lt;/p&gt;


	&lt;p&gt;In the end I used this little bit of code which worked a treat:&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;return amount.gsub(/[&#163;,]/,&amp;#8217;&amp;#8216;)&lt;/strong&gt;&lt;/p&gt;


	&lt;p&gt;So what this does is matches the characters &#163; and , and substitutes them with blank. Works a treat.&lt;/p&gt;</description>
      <pubDate>Wed, 18 Jan 2006 06:46:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:da073b29269d84a26bf737a59b487d90</guid>
      <author>paul</author>
      <link>http://blog.pauldalton.co.uk/articles/2006/01/18/snippet-cleaning-up-currency-strings</link>
      <category>Rails</category>
    </item>
    <item>
      <title>Rails Express blog</title>
      <description>&lt;p&gt;&lt;a href="http://railsexpress.de/blog/"&gt;The rails express blog&lt;/a&gt; written by &lt;a href="http://railsbench.rubyforge.org/"&gt;Stefan Kaes, author of railsbench&lt;/a&gt;  is a great resource for anyone interested in wringing a bit (or a lot in some cases) more performance out of  Ruby on Rails.&lt;/p&gt;


	&lt;p&gt;Some great tips on there.&lt;/p&gt;


	&lt;p&gt;Good stuff.&lt;/p&gt;</description>
      <pubDate>Tue, 29 Nov 2005 09:39:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:ea6ae7a3798d2328a0b88b53b9f08615</guid>
      <author>paul</author>
      <link>http://blog.pauldalton.co.uk/articles/2005/11/29/rails-express-blog</link>
      <category>Rails</category>
      <category>linkage</category>
    </item>
    <item>
      <title>Rails, Mysql native bindings 2.7 on Centos</title>
      <description>&lt;p&gt;&lt;a href="http://weblog.rubyonrails.com/archives/2005/10/30/get-10-15-more-performance-with-mysql-rails"&gt;This post over on the RoR blog&lt;/a&gt; a few days back talks about upgrading to the new mysql native bindings for ruby to get the best performance.&lt;/p&gt;


	&lt;p&gt;However, I&amp;#8217;ve been unable to get it to install using gem, a la :&lt;/p&gt;


&lt;code&gt;
gem install mysql
&lt;/code&gt;

	&lt;p&gt;as I have been getting compile errors:&lt;/p&gt;


&lt;code&gt;
ERROR: While executing gem - (RuntimeError) ERROR:
Failed to build gem native extension. 
&lt;/code&gt;

	&lt;p&gt;Despite the number of solutions to this out there, I&amp;#8217;ve only now found one that works with my particular setup, namely centos 4.2, and that can be found in &lt;a href="http://ocsforums.com/showthread.php?p=462"&gt;this post&lt;/a&gt;&lt;/p&gt;


I should point out that I didn&amp;#8217;t need to edit the makefile or anything, I just ran make, make install in the 
&lt;code&gt;
/usr/local/lib/ruby/gems/1.8/gems/mysql-2.7
&lt;/code&gt;
folder.

	&lt;p&gt;All working now, which is nice.&lt;/p&gt;</description>
      <pubDate>Tue, 08 Nov 2005 16:58:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:929506914801db8815bd08699dd48f75</guid>
      <author>paul</author>
      <link>http://blog.pauldalton.co.uk/articles/2005/11/08/rails-mysql-native-bindings-2-7-on-centos</link>
      <category>Rails</category>
    </item>
    <item>
      <title>How to count the number of records in a table...</title>
      <description>&lt;p&gt;Want to find out how many records there are in a table?&lt;/p&gt;


	&lt;p&gt;You could do a table.&lt;code&gt;&amp;lt;a href="http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M000674"&amp;gt;find_by_sql &amp;lt;/a&amp;gt; "select count(*) from table",&lt;/code&gt;&lt;/p&gt;


	&lt;p&gt;You could get all the records from the table and then count them, say &lt;code&gt;records = table.find(:all)&lt;/code&gt;.&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;Or&lt;/strong&gt; you could do count = &lt;a href="http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M000683"&gt;table.count&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;How cool is that!&lt;/p&gt;</description>
      <pubDate>Wed, 28 Sep 2005 11:30:55 +0100</pubDate>
      <guid isPermaLink="false">urn:uuid:dacd6302f24dbeb25eb2fb22ff576ea8</guid>
      <author>paul</author>
      <link>http://blog.pauldalton.co.uk/articles/2005/09/28/how-to-count-the-number-of-records-in-a-table</link>
      <category>General</category>
      <category>Rails</category>
    </item>
    <item>
      <title>ruby on rails country_options_for_select helper</title>
      <description>&lt;p&gt;So I&amp;#8217;m still working away on this project using &lt;a href="http://www.rubyonrails.org/"&gt;Ruby on Rails&lt;/a&gt;, and generally I&amp;#8217;m loving it. It really is a great piece of software. Progress is good, but I often find myself stumbling on what should be the simple things.&lt;/p&gt;


	&lt;p&gt;Today for example, I wanted to use the country_options_for_select() form helper to generate a list of countries as a dropdown in a form, with a number of countries prioritised at the top of the list.&lt;/p&gt;


The list was being generated but the prioritised countries where not be generated. The code I had was something like this:
&lt;code&gt;country_options_for_select(priority_countries = ['United Kingdom','United States'])&lt;/code&gt;.

	&lt;p&gt;Now the &lt;a href="http://api.rubyonrails.com/classes/ActionView/Helpers/FormOptionsHelper.html#M000330"&gt;method signature in the api docs&lt;/a&gt; is this: &lt;code&gt;country_options_for_select(selected = nil, priority_countries = nil)&lt;/code&gt;, and I &lt;em&gt;assumed&lt;/em&gt; that the &lt;code&gt;selected = nil&lt;/code&gt; didn&amp;#8217;t need to be included as it was the default.&lt;/p&gt;


	&lt;p&gt;Not so. Once I added the &lt;code&gt;selected = nil&lt;/code&gt; argument to the method it worked.&lt;/p&gt;


	&lt;p&gt;And the lesson is?&lt;/p&gt;


	&lt;p&gt;Assumption is the mother of all feck ups I guess.&lt;/p&gt;</description>
      <pubDate>Fri, 23 Sep 2005 00:21:55 +0100</pubDate>
      <guid isPermaLink="false">urn:uuid:070c0b8feaf631c1631faf851a8d7fb9</guid>
      <author>paul</author>
      <link>http://blog.pauldalton.co.uk/articles/2005/09/23/ruby-on-rails-country_options_for_select-helper</link>
      <category>General</category>
      <category>Rails</category>
    </item>
    <item>
      <title>Formatting dates in rails templates using strftime()</title>
      <description>&lt;p&gt;Recently I needed to be able to format a date that I had retrieved from the database into something more readable. In smarty one would do something like &lt;code&gt;$date|date_format&lt;/code&gt; but I could not find anything like that in ruby.&lt;/p&gt;


	&lt;p&gt;Then someone pointed out that the date field in the database would be recognised as such and would be a date object in my View.&lt;/p&gt;


	&lt;p&gt;As the date is a Date object I can use &lt;a href="http://www.ruby-doc.org/core/classes/Time.html#M000236"&gt;strftime()&lt;/a&gt; to reformat the date any way I want to. 
eg. &lt;code&gt;@event.start_date.strftime("%d %B %Y")&lt;/code&gt;&lt;/p&gt;</description>
      <pubDate>Tue, 23 Aug 2005 15:07:38 +0100</pubDate>
      <guid isPermaLink="false">urn:uuid:adbd7922ccc8f7d929b7044f3aba3609</guid>
      <author>paul</author>
      <link>http://blog.pauldalton.co.uk/articles/2005/08/23/formatting-dates-in-rails-templates-using-strftime</link>
      <category>Rails</category>
    </item>
    <item>
      <title>How to find the id of a record you have just created in ruby on rails?</title>
      <description>&lt;p&gt;How do you get the id of a record you have just created in &lt;a href="http://www.rubyonrails.org"&gt;Ruby on Rails&lt;/a&gt;?&lt;/p&gt;


	&lt;p&gt;Well, the answer to this question came up on the rails mail list recently.&lt;/p&gt;


	&lt;p&gt;It goes something a little bit like this:&lt;/p&gt;


&lt;code&gt;
   @text.save   //insert something into the database
   @text.id      //get the id of the new record 
&lt;/code&gt;</description>
      <pubDate>Thu, 21 Jul 2005 18:00:53 +0100</pubDate>
      <guid isPermaLink="false">urn:uuid:d8f269914e4633751288bb6389cc4948</guid>
      <author>paul</author>
      <link>http://blog.pauldalton.co.uk/articles/2005/07/21/how-to-find-the-id-of-a-record-you-have-just-created-in-ruby-on-rails</link>
      <category>Rails</category>
    </item>
  </channel>
</rss>
