<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>paulsturgess.co.uk articles</title>
    <link>http://www.paulsturgess.co.uk/archive</link>
    <description>paulsturgess.co.uk Ruby on Rails articles</description>
    <item>
      <title>Free Ruby on Rails security e-book</title>
      <link>http://www.paulsturgess.co.uk/articles/show/74-free-ruby-on-rails-security-e-book</link>
      <description>&lt;p&gt;The the ever so useful Ruby on Rails security blog, &lt;a href="http://www.rorsecurity.info"&gt;rorsecurity&lt;/a&gt;, has released a &lt;a href="http://www.rorsecurity.info/the-book/"&gt;free e-book&lt;/a&gt;.&lt;/p&gt;

</description>
      <guid>http://www.paulsturgess.co.uk/articles/show/74-free-ruby-on-rails-security-e-book</guid>
    </item>
    <item>
      <title>Hoptoad - Free ruby on rails exception catcher</title>
      <link>http://www.paulsturgess.co.uk/articles/show/73-hoptoad---free-ruby-on-rails-exception-catcher</link>
      <description>&lt;p&gt;I've been using the &lt;a href="http://github.com/rails/exception_notification/tree/master"&gt;exception_notification&lt;/a&gt; plugin for sometime now. It's been a life saver on many occassion, allowing me to be made aware of bugs at the earliest opportunity.&lt;/p&gt;

&lt;p&gt;However, there are occassions where you don't necessarily require multiple emails all notifying you of the same problem. This is where &lt;a href="http://www.hoptoadapp.com/welcome"&gt;Hoptoad&lt;/a&gt; comes in handy.&lt;/p&gt;

&lt;p&gt;It catches all your exceptions and holds them online, grouping them together and giving you a single notification.&lt;/p&gt;

&lt;p&gt;It's free and easy to 'drop in' as a replacement for exception notifier.&lt;/p&gt; </description>
      <guid>http://www.paulsturgess.co.uk/articles/show/73-hoptoad---free-ruby-on-rails-exception-catcher</guid>
    </item>
    <item>
      <title>Can't activate rubyforge</title>
      <link>http://www.paulsturgess.co.uk/articles/show/72-cant-activate-rubyforge</link>
      <description>&lt;p&gt;I just tried to start one of my rails apps and got...&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Can't activate rubyforge (= 0.4.4, runtime), already activated rubyforge-1.0.0 (Gem::Exception)&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I fixed it by uninstalling rubyforge completely and thus getting rid of version 0.4.4 and reinstalling to have just version 1.0.0.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo gem uninstall -a rubyforge&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Confirming that I didn't mind the warning that 'one or more dependencies will not be met'.&lt;/p&gt;

&lt;p&gt;Then reinstalling it with...&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;sudo gem install rubyforge&lt;/code&gt;&lt;/pre&gt;
</description>
      <guid>http://www.paulsturgess.co.uk/articles/show/72-cant-activate-rubyforge</guid>
    </item>
    <item>
      <title>"Only get, head, post, put, and delete requests are allowed. Ruby on Rails error"</title>
      <link>http://www.paulsturgess.co.uk/articles/show/71-only-get-head-post-put-and-delete-requests-are-allowed-ruby-on-rails-error</link>
      <description>&lt;p&gt;Every so often I get the rather odd Ruby on Rails error "Only get, head, post, put, and delete requests are allowed."&lt;/p&gt;

&lt;p&gt;So far, each time a simple restart of my local server has done the trick and made it go away.&lt;/p&gt;</description>
      <guid>http://www.paulsturgess.co.uk/articles/show/71-only-get-head-post-put-and-delete-requests-are-allowed-ruby-on-rails-error</guid>
    </item>
    <item>
      <title>Using or equals (||=) to set variables in Ruby on Rails</title>
      <link>http://www.paulsturgess.co.uk/articles/show/70-using-or-equals-to-set-variables-in-ruby-on-rails</link>
      <description>&lt;p&gt;Using 'or equals' is great for creating and setting variables when they don't exist - useful for default values. &lt;/p&gt;

&lt;pre&gt;&lt;code class="ruby"&gt;&gt;&gt;foo
=&gt;NameError: undefined local variable or method `foo' for main:Object
&gt;&gt;foo ||= "bar"
=&gt;"bar"&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;If variable already exists then it isn't overwritten:&lt;/p&gt;

&lt;pre&gt;&lt;code class="ruby"&gt;&gt;&gt;foo = "hello"
=&gt; "hello"
&gt;&gt;foo ||= "goodbye"
=&gt;"hello"&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I use this in partials sometimes where I'm expecting a local variable to be passed in but if there isn't one I'd like there to be a default.&lt;/p&gt; 

&lt;p&gt;It also means if the variable isn't passed in then you wont get an undefined error.&lt;/p&gt;

&lt;p&gt;However, there is a gotcha you want to look out for. Observe:&lt;/p&gt;

&lt;pre&gt;&lt;code class="ruby"&gt;&gt;&gt;foo = false
=&gt; false
&gt;&gt;foo ||= true
=&gt;true&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The or equals actually checks if the left hand side evaluates to true and if so it isn't changed.&lt;/p&gt;

&lt;p&gt;So the or equals is not useful for booleans. It's not difficult to work around that but it is something to keep in mind...&lt;/p&gt;
&lt;pre&gt;&lt;code class="ruby"&gt;&gt;&gt; foo = false
=&gt; false
&gt;&gt; foo = true if foo.nil?
=&gt; false&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Not quite as nice but it's one way to do the job.&lt;/p&gt;</description>
      <guid>http://www.paulsturgess.co.uk/articles/show/70-using-or-equals-to-set-variables-in-ruby-on-rails</guid>
    </item>
    <item>
      <title>Some handy shortcuts for Textmate, Vim and the command line.</title>
      <link>http://www.paulsturgess.co.uk/articles/show/69-some-handy-shortcuts-for-textmate-vim-and-the-command-line</link>
      <description>&lt;p&gt;These are probably my most used shortcuts:&lt;/p&gt;

&lt;h4&gt;Textmate&lt;/h4&gt;
&lt;p&gt;ctrl+shift+&amp;gt; = open and close erb tags &amp;lt;% = %&amp;gt;&lt;/p&gt;
&lt;p&gt;alt+command+] = auto indent highlighted code&lt;/p&gt;
&lt;p&gt;ctrl+shift+w = auto put html tags around highlighted code&lt;/p&gt;
&lt;p&gt;alt+command+&amp;gt; = auto close tag&lt;/p&gt;
&lt;p&gt;ctrl+command+w = close all open tabs&lt;/p&gt;
&lt;p&gt;alt+command+a = type on the end of multiple lines of highlighted code&lt;/p&gt;

&lt;h4&gt;VIM&lt;/h4&gt;
&lt;p&gt;o - is new line&lt;/p&gt;
&lt;p&gt;d, shift g - clears the file (d is delete and capital g is bottom of the file)&lt;/p&gt;
&lt;p&gt;:set number - turn on line numbers&lt;/p&gt;
&lt;p&gt;18, shift g - goes to line 18&lt;/p&gt;
&lt;p&gt;dd - deletes a line&lt;/p&gt;

&lt;h4&gt;Command line&lt;/h4&gt;
&lt;p&gt;ctrl+r - searches through recent commands (repeat to keep searching)&lt;/p&gt;
&lt;p&gt;ctrl+a - beginning of the line&lt;/p&gt;
&lt;p&gt;ctrl+e - end of line&lt;/p&gt;</description>
      <guid>http://www.paulsturgess.co.uk/articles/show/69-some-handy-shortcuts-for-textmate-vim-and-the-command-line</guid>
    </item>
    <item>
      <title>Viewing the documentation for your installed gems for Ruby on Rails</title>
      <link>http://www.paulsturgess.co.uk/articles/show/68-viewing-the-documentation-for-your-installed-gems-for-ruby-on-rails</link>
      <description>&lt;p&gt;To view the rdoc for your installed gems, at the command line type:&lt;/p&gt;

&lt;pre&gt;&lt;code class="ruby"&gt;gem server&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Then point your browser at http://localhost:8808 &lt;/p&gt;</description>
      <guid>http://www.paulsturgess.co.uk/articles/show/68-viewing-the-documentation-for-your-installed-gems-for-ruby-on-rails</guid>
    </item>
    <item>
      <title>Using routes in models in Ruby on Rails</title>
      <link>http://www.paulsturgess.co.uk/articles/show/67-using-routes-in-models-in-ruby-on-rails</link>
      <description>&lt;p&gt;To use routes in your model just add the following to config/environment.rb...&lt;/p&gt;

&lt;pre&gt;&lt;code class="ruby"&gt;
class ActiveRecord::Base
 include ActionController::UrlWriter

 host = case ENV['RAILS_ENV']
 when "production"
   "yourlivedomain.com"
 when "development"
   "localhost:3000"
 end
 default_url_options[:host] = host
end
&lt;/code&gt;&lt;/pre&gt;

 </description>
      <guid>http://www.paulsturgess.co.uk/articles/show/67-using-routes-in-models-in-ruby-on-rails</guid>
    </item>
    <item>
      <title>Assigning a body class to your page layout in Ruby on Rails</title>
      <link>http://www.paulsturgess.co.uk/articles/show/66-assigning-a-body-class-to-your-page-layout-in-ruby-on-rails</link>
      <description>&lt;p&gt;In your controller create a private method thus:&lt;/p&gt;

&lt;pre&gt;&lt;code class="ruby"&gt;private

def add_body_class(new_class)
  @body_class ||= ""
  @body_class &lt;&lt; " #{new_class}"
end&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Then in your controller actions you can add a body class with:&lt;/p&gt;

&lt;pre&gt;&lt;code class="ruby"&gt;add_body_class "two_col"&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The reason for the &lt;code&gt;add_body_class&lt;/code&gt; method is so that you can easily add multiple classes without worrying if you have already set the body_class instance variable.&lt;/p&gt;

&lt;p&gt;I find this useful because quite often I will use a before filter to set a generic body class for every action in the controller...&lt;/p&gt;

&lt;pre&gt;&lt;code class="ruby"&gt;before_filter :set_body_class

private
def set_body_class
  add_body_class "some_section_name"
end&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;To output &lt;code&gt;@body_class&lt;/code&gt; replace your layout body tag with this:&lt;/p&gt;

&lt;pre&gt;&lt;code class="ruby"&gt;&amp;lt;body&amp;lt;%= (@body_class.nil?) ? &amp;quot;&amp;quot; : &amp;quot; class=&amp;#39;#{@body_class}&amp;#39;&amp;quot; %&amp;gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That's basically a one line if statement that checks if &lt;code&gt;@body_class&lt;/code&gt; exists before setting the class on the body tag.&lt;/p&gt;</description>
      <guid>http://www.paulsturgess.co.uk/articles/show/66-assigning-a-body-class-to-your-page-layout-in-ruby-on-rails</guid>
    </item>
    <item>
      <title>Getting Ruby on Rails &amp; mysql setup on a Mac OSX Leopard clean install</title>
      <link>http://www.paulsturgess.co.uk/articles/show/65-getting-ruby-on-rails-mysql-setup-on-a-mac-osx-leopard-clean-install</link>
      <description>&lt;p&gt;So Rails is already installed on Leopard but you'll probably want to update it to the latest version. So first you need to install the make tools from your Leopard disc:&lt;/p&gt;

&lt;p&gt;Leopard CD &gt; Optional Installs &gt; Xcode Tools &gt; XcodeTools.mpkg&lt;/p&gt;

&lt;p&gt;Update Rails and all the other gems:&lt;/p&gt;

&lt;pre&gt;&lt;code class="ruby"&gt;sudo gem update --include-dependencies&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now for mysql. You can download a pre-built package from their site &lt;a href="http://dev.mysql.com/downloads/mysql/5.0.html#macosx-dmg"&gt;http://dev.mysql.com/downloads/mysql/5.0.html#macosx-dmg&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note that you don't have to register - you can skip past it using the link after the form.&lt;/p&gt;

&lt;p&gt;The start up package doesn't work (at the time of writing). However, I found a &lt;a href="http://blog.tomatocheese.com/archives/2007/11/1/migrating_mysql_to_mac_os_x_leopard/"&gt;work around&lt;/a&gt;. I'll include the instructions here as well:&lt;/p&gt;

&lt;p&gt;First download this &lt;a href="http://paulsturgess.co.uk/files/com.mysql.mysqld.plist"&gt;MySQL launchd configuration file&lt;/a&gt;

&lt;pre&gt;&lt;code&gt;sudo mv Downloads/com.mysql.mysqld.plist /Library/LaunchDaemons/
sudo chown root /Library/LaunchDaemons/com.mysql.mysqld.plist
sudo chown -R mysql /usr/local/mysql-5.0.51a-osx10.5-x86/ /usr/local/mysql
sudo launchctl load /Library/LaunchDaemons/com.mysql.mysqld.plist&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;To allow you to just type 'mysql' from the command line:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;vi ~/.bash_profile&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Enter the following into the file&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;export PATH="$PATH:/usr/local/mysql/bin"&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Restart terminal and mysql is all setup and will start every time you reboot.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://weblog.rubyonrails.org/2007/10/26/today-is-leopard-day"&gt;DHH recommends&lt;/a&gt; you install the mysql C bindings like thus:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Job done!&lt;/p&gt;

&lt;p&gt;Leopard comes with mongrel and svn and lots of other goodies out of the box! Have a look with:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;gem list&lt;/code&gt;&lt;/pre&gt;</description>
      <guid>http://www.paulsturgess.co.uk/articles/show/65-getting-ruby-on-rails-mysql-setup-on-a-mac-osx-leopard-clean-install</guid>
    </item>
  </channel>
</rss>
