Paul Sturgess

How to include class and validation methods using a module in Ruby On Rails


almost 8 years ago by Paul Sturgess on paulsturgess.co.uk articles.
A great way to re-use code across your Ruby on Rails application is to use a module and include the methods contained within it where you need them. You...

Format a string for use as a filename in Ruby


almost 8 years ago by Paul Sturgess on paulsturgess.co.uk articles.
Often in Rails apps I want to take a string and use it for the filename of a document. Here's a method I use to extend the string class, I just put it inside...

How to efficiently perform a bulk update of lots of records in Ruby on Rails


almost 8 years ago by Paul Sturgess on paulsturgess.co.uk articles.
If you are looking to update a lot of database records at once in Ruby on Rails then it's worth considering the different ways it can be done and which...

jQuery text slide up / slide down effect


almost 8 years ago by Paul Sturgess on paulsturgess.co.uk articles.
On the Guardian newspaper website they use a jQuery text slide up / slide down effect when you hover over the images. I've recreated the effect here but...

Missing these required gems: RedCloth - config.gem Ruby on Rails error


almost 8 years ago by Paul Sturgess on paulsturgess.co.uk articles.
RedCloth is one of those gems that is not consistently named and has caused me problems in the past. This time even though I had specified it's requirement...

How to freeze gems in Ruby on Rails


almost 8 years ago by Paul Sturgess on paulsturgess.co.uk articles.
It's always a good idea to freeze your gems in your Ruby on Rails app when you don't have full control over your hosting environment. To freeze any gems...

A Ruby on Rails will_paginate gotcha


almost 8 years ago by Paul Sturgess on paulsturgess.co.uk articles.
Here's a cheeky gotcha to keep an eye out for when using the popular pagination plugin/gem for Ruby on Rails will_paginate I was doing something like.Foo...

Ruby on Rails sort_by vs sort


almost 8 years ago by Paul Sturgess on paulsturgess.co.uk articles.
Given the choice when sorting arrays in Ruby it's typically better to use sort_by rather than sort. sort_by uses the Schwartzian transform technique that...

Using named scopes (named_scope) in Ruby on Rails


over 7 years ago by Paul Sturgess on paulsturgess.co.uk articles.
Ruby on Rails 2.1 introduced the notion of a Named Scope. For me it's easily been one of the most beneficial features in helping to keep my code 'DRY'.Essentially...

How to install a Ruby on Rails plugin from a specific git repository branch


over 7 years ago by Paul Sturgess on paulsturgess.co.uk articles.
Lots of Ruby on Rails plugins are being updated for Rails 3 and thus for older Rails apps you don't always want to install the latest and greatest version...