Paul Sturgess

How to run certain lines of code in only production or development mode in Ruby on Rails


almost 10 years ago by Paul Sturgess on paulsturgess.co.uk articles.
Often I don't want to fire off emails to the site admin when I'm testing things on my local machine. That's when the following comes in really handy..ENV...

Evaluating all items in an array in Ruby on Rails


almost 10 years ago by Paul Sturgess on paulsturgess.co.uk articles.
The all method allows you to pass each element of the collection to the block. The result will only be true if none of the items in the array evaluate to...

Allowing users to post youtube videos to your Ruby on Rails web app


almost 10 years ago by Paul Sturgess on paulsturgess.co.uk articles.
This method allows your users to post youtube videos without exposing yourself to the vulnerabilities of them pasting in any script they like. They can...

Getting Ruby on Rails & mysql setup on a Mac OSX Leopard clean install


almost 10 years ago by Paul Sturgess on paulsturgess.co.uk articles.
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...

Assigning a body class to your page layout in Ruby on Rails


over 9 years ago by Paul Sturgess on paulsturgess.co.uk articles.
In your controller create a private method thus: private def add_body_class(new_class) @body_class ||= "" @body_class Then in your controller actions...

Using routes in models in Ruby on Rails


over 9 years ago by Paul Sturgess on paulsturgess.co.uk articles.
To use routes in your model just add the following to config/environment.rb... class ActiveRecord::Base include ActionController::UrlWriter host =...

Viewing the documentation for your installed gems for Ruby on Rails


over 9 years ago by Paul Sturgess on paulsturgess.co.uk articles.
To view the rdoc for your installed gems, at the command line type: gem server Then point your browser at http://localhost:8808 ...

Some handy shortcuts for Textmate, Vim and the command line.


over 9 years ago by Paul Sturgess on paulsturgess.co.uk articles.
These are probably my most used shortcuts: Textmate ctrl+shift+> = open and close erb tags alt+command+] = auto indent highlighted code ctrl+shift+w ...

Using or equals (||=) to set variables in Ruby on Rails


over 9 years ago by Paul Sturgess on paulsturgess.co.uk articles.
Using 'or equals' is great for creating and setting variables when they don't exist - useful for default values. >>foo =>NameError: undefined local variable...

"Only get, head, post, put, and delete requests are allowed. Ruby on Rails error"


over 9 years ago by Paul Sturgess on paulsturgess.co.uk articles.
Every so often I get the rather odd Ruby on Rails error "Only get, head, post, put, and delete requests are allowed." So far, each time a simple restart...