Snippets archive
-
Assigning a body class to your page layout in Ruby on Rails
A quick, simple method
-
Getting Ruby on Rails & mysql setup on a Mac OSX Leopard clean install
Quick guide to getting Rails going in a clean install of Leopard
-
Allowing users to post youtube videos to your Ruby on Rails web app
A method that wont compromise your security
-
How to run certain lines of code in only production or development mode in Ruby on Rails
Sometimes you only want something to happen in production mode
-
Evaluating all items in an array in Ruby on Rails
Need to know if all items in an array evaluate to the same thing?
-
Undefined method `require_gem' for main:Object
Change 'require_gem' to just 'gem'
-
method_missing: undefined method server_settings= for ActionMailer::Base:Class (NoMethodError)
server_settings has been deprecated in Rails 2, change it for smtp_settings
-
Running old Ruby on Rails apps when you have Rails 2.x installed
rake rails:update
-
How to use Capistrano 1.x to deploy Ruby on Rails apps when you have Cap 2.x
cap _1.4.1_ deploy
-
Porticus - A Graphical User Interface for MacPorts on OS X
Check out Porticus
-
How to find out where your ruby and ruby on rails gems are installed on OS X
"gem env gemp"
-
Wrong number of arguments (0 for 1) on notifiy method in Ruby on Rails
A Rails gotcha, the notify method is already taken.
-
How to destroy an array of objects with one line of code in Ruby on Rails
A useful one liner for deleting multiple objects all at once
-
Site update
I try to avoid posting anything other than Ruby on Rails related posts but I thought i'd better mention the changes i've just uploaded to this site.
-
Calling dynamic methods in Ruby on Rails
To utilise dynamic method names in Ruby on Rails you can use Ruby's send method to pass a message to an object.
-
Using ruby methods map and zip along with Rails extended finds
This is a combination of techniques that I find useful when you need to output related data from various database tables in the same list.
-
Counter_cache in ruby on rails 1.2.2
Using counter_cache in ruby on rails
-
Using helper methods in Ruby on Rails
A quick and simple intro to using helper methods in Ruby on Rails.
-
Using constants in environment.rb in Ruby on Rails
Constants are handy for keeping your code and output consistent.
-
Deploying two rails apps under the same account using SVN and Capistrano on hostingrails.com
I'll show you how I have my deploy file setup so that I can deploy either a test or live version of my site up to the server.
-
Using MacPorts(DarwinPorts) to install Ruby on Rails, MySQL, Subversion, Capistrano and Mongrel on Mac OS X
MacPorts package manager is great way to install Ruby on Rails on OS X. I'll explain how I used it.
-
Using blank and compact in Ruby on Rails to help output incomplete data
A convenient method for outputing a set of address fields without having to check each one individually if it is blank.
-
How to display the file name of an upload in Ruby on Rails
If you allow users to upload files you often want to display the filename of the file they uploaded.
-
New host, new look and feel, new functionality
I've made quite a few improvements to the site, I'll explain what's changed.
-
How to automatically pluralize text in Ruby on Rails
Rails has a really useful text helper that will automatically pluralize a word for you.
-
How to specify multiple layouts within the same controller in Ruby on Rails
Sometimes you want actions to use specific layouts, different from the other actions in the controller.
-
Ruby on Rails on OS X with Mongrel and MySQL
Quick notes for how I got Ruby on Rails running on my MacBook (OS X Tiger)
-
Debugging tips in Ruby on Rails
A few different methods to go about solving that bug in your application.
-
How to specify the number of decimal places displayed in Ruby on Rails
This is another Ruby class method that can be easily utilised to specify the number of decimal places to show.
-
How to truncate text in Ruby on Rails
Sometimes it's handy to only outout a certain amount of text. This is where the truncate function comes in really handy.
-
How to check if a file exists in Ruby on Rails
A great way of ensuring you don't get dead links from file uploads that don't work.
-
How to evaluate the size of a file upload in Ruby on Rails
Combining File.size and number_to_human_size make it easy to show the size of a file.
-
How to build a simple ajax search in Ruby on Rails
A simple, quick and easy way to get an ajax search built.
-
How to write custom validation in Ruby on Rails
Custom validation is great for writing those extra methods that aren't covered by the built in validation in Rails.
-
Custom foreign keys in ruby on rails
I wanted to create a custom foreign key that pointed to the same table as another foreign key
-
undefined method `body=' NoMethodError in Ruby on Rails
Another day, another gotcha. Trying to use an instance variable @response isn't a good idea.
-
wrong argument type String (expected Module) Ruby on Rails error
A Ruby on Rails gotcha. In my case I was trying to create a select drop down for a field called 'type', which happens to be a reserved word.
-
Paginate the results of a query in Ruby on Rails
Sometimes you don't want to just use the default find all when paginating.
-
How to assign a css class or id to link_to method in Ruby on Rails
It's so simple to do but so easy to forget how.
-
Using routes.rb to help you structure your Ruby on Rails app
There's loads of clever things you can do with routes.rb. I'll explain how I use them and how it can effect the way you structure your app.
-
Printing the alphabet easily in Ruby on Rails
Sometimes you need to print the alphabet for pagination or a search by letter. With Ruby there's no need to type each letter out.
-
Spring CSS Reboot - Out of the dark and into the light
The dark browns have been swapped for creams - I've written a new stylesheet to take part in the Spring CSS Reboot!
-
How to pass an instance variable to a rendered partial in Ruby on Rails
Sometimes it's useful to use the same partial to display different arrays of data in the same way.
-
Select and collect with conditions in Ruby on Rails
How to return an option collection that is filtered by a condition.
-
How to combine multiple conditions in a find statement in Ruby on Rails
How to put more than one condition into a find statement.
-
How to output a boolean true or false to display yes or no in Ruby on Rails
Displaying true/false doesn't look so good, it's nice and easy to show yes/no or whatever you like.
-
How to add a css class to start_form_tag in Ruby on Rails
It's not immediately obvious, but i've found a way to do it.
-
Passing variables between views and layout templates with Ruby on Rails
Did you know you can pass variables from a view to a layout?
-
Why you should freeze Rails on a shared host environment
There's always a danger that your host may upgrade its' version of Rails. I'll explain how to make sure your site doesn't break.
-
Pure CSS method to indicate the page you are on
There's no need to use php/asp programming to change classes on your navigation.
-
Using del.icio.us to display links on your website
The links displayed on the side panel are all bookmarks pulled direct from my del.icio.us account.
-
Alternate row classes with Ruby on Rails
Great for colouring rows alternately.
-
Backing up your database with a cron job on Bluehost
I use a cron job to email me a backup of my database every day.
-
Creating an RSS feed in Ruby on Rails
Once again Ruby on Rails makes things so easy; how to set up an RSS feed on your site.
-
How to format dates in Ruby on Rails
Formatting dates in Ruby on Rails is easy.
-
A footer that stays at the bottom of the browser window
My footer stays at the bottom of the browser window or the content, depending on which is longest.
-
Tagging with Ruby on Rails
How I set up the tagging system I have for the articles on this site.
-
Getting Ruby on Rails running on Bluehost
Getting my first Ruby on Rails application up and running on Bluehost was never going to be simple. Hopefully other developers can benefit from my experience.
-
paulsturgess.co.uk relaunch
The first post on my relaunched website. Completely new look and feel, all built using Ruby on Rails. I hope you like it.
About
Paul is a web developer for Kyanmedia web agency. He's lucky enough to write in Ruby on Rails full-time and uses this site to post snippets of code.
Contact
my name at gmail.com
More snippets
Take a look in the archive
Need a website?
Contact my employer. Make sure to check out our portfolio of work.
Hosting
I recommend hostingrails.com