undefined method `body=' NoMethodError in Ruby on Rails


~11 years ago by Paul Sturgess on paulsturgess.co.uk articles.
Not a reserved word or magic fieldname this time. But apparantly "response" is something special in Rails, "request" is too. So when I attempted to use...

Using del.icio.us to display links on your website


~11 years ago by Paul Sturgess on paulsturgess.co.uk articles.
Originally I had written a link manager into the admin for this site until I decided del.icio.us was the best way to manage my bookmarks. The reason for...

Custom foreign keys in ruby on rails


~11 years ago by Paul Sturgess on paulsturgess.co.uk articles.
Custom foreign keys in Rails are handy if you have a legacy database where you cannot change table/field names. In my case it wasn't to do with a legacy...

Pure CSS method to indicate the page you are on


~11 years ago by Paul Sturgess on paulsturgess.co.uk articles.
The idea of this method is to allow you to target a specific navigation item with css. You must place a unique id on the body of each page in your site...

How to write custom validation in Ruby on Rails


~11 years ago by Paul Sturgess on paulsturgess.co.uk articles.
Fortunately writing custom validation is really easy in Rails. Let me show you... def validate errors.add_to_base "If you are attaching a file you...

Why you should freeze Rails on a shared host environment


~11 years ago by Paul Sturgess on paulsturgess.co.uk articles.
When you upload your site you need to run the freeze gems rake command. Freeze is cool according to David Heinemeier Hansson and it will ensure your site...

How to build a simple ajax search in Ruby on Rails


~11 years ago by Paul Sturgess on paulsturgess.co.uk articles.
I've just implemented a simple ajax search on my site and i'm going to explain how I did it. In my view: <%= start_form_tag({}, {:id => "search...

Passing variables between views and layout templates with Ruby on Rails


~11 years ago by Paul Sturgess on paulsturgess.co.uk articles.
One of the most useful discoveries I have made with Rails is the ability to pass variables from a layout to a view and vice versa. This means I can set...

How to evaluate the size of a file upload in Ruby on Rails


~11 years ago by Paul Sturgess on paulsturgess.co.uk articles.
Sometimes it's useful to show how large a file is on a wesite. If anything, showing the file size allows the user to guage roughly how long it's going to...

How to add a css class to start_form_tag in Ruby on Rails


~11 years ago by Paul Sturgess on paulsturgess.co.uk articles.
To add a class to a form in Ruby on Rails using start_form_tag isn't immediately obvious. I achieved it like this: <%= start_form_tag( {}, {:class...