Feed items

Using Rack Middleware in Rails3

I was just looking into including some Rack middleware in my Rails 3 app. One thing confused me slightly. There seems to be two ways that you can include middleware in you app:-

1. config.ru

2. application.rb

Note: I'm using the codehighlighter rack middleware for this example.

Disable ActiveRecord in Rails 3

Came up against this recently when trying to upgrade a Rails app which was using MongoDB. Obviously I didn't want to use ActiveRecord, so I set about removing it.

The old way of removing ActiveRecord was to place this line in the environment.rb file, "config.frameworks -= [ :active_record ]". However, in Rails 3 you can simply pass the "-O" switch to the rails command, like so:-

 rails yourapp -O

But what if you've already created your app? If you look in your config/application.rb file, you'll see this line at the top:-

Using Prototype and JQuery with Rails3 (UJS)

I've been look for some information on the unobtrusive javascript features in Rails 3, and it turns out that there's not much out there! Either that, or I'm looking in the wrong places.

So here is my attempt to explain some of the features. I'll create two sample blog apps, one using Prototype and the other using JQuery (the code is available on github).

Install Rails 3

If you haven't already, get Rails 3 installed. Everything you need to know is here.

Sorting an EmbeddedDocument with MongoMapper

I had this issue recently when trying to sort items in an EmbeddedDocument. Say you have a "Post" Document and a "Comment" EmbeddedDocument. If you want to sort the comments by the created_at field (which is pretty likely), it isn't as easy as you would think, using MongoMapper (at the moment anyway).

However, there is a nice clean alternative that can be used to achieve the same results. Simply use the "sort_by" method like so, passing in a symbol of the field to sort as a proc:-

A look at themes with Compass (Part 1)

As you may of heard, I'm working on a new project (meetee), which will allow a more collaborative approach to meetings.

Over the last few days I've concentrating my efforts on getting the website design implemented using the following technologies:-

  • Ruby on Rails
  • MongoDB
  • Compass CSS Framework

I've written about Compass before, and in this article (and the next) I want to concentrate on how I dealt with setting up themes.

Sunspot Full-text Search for Rails/Ruby

Sunspot

I had the recent pleasure of using Sunspot, which is powered by Apache Solr, to provide full-text search functionality for a Ruby on Rails recent project.

Installation/Configuration

Installing Sunspot is reasonably simple. I installed the Sunspot gems along with the related Sunspot Rails Plugin, with the following commands:-

Sunspot gems

Sass and the Compass Framework

My Experience with Compass

So, as you may have noticed, I have given the site a bit of a make over... and I thought it may be nice to make my first post be about the tools that I used to create the new look. In particular I want to talk about the wonderful Compass CSS framework.

Nested Object Forms in Rails 2.3

The Problem

If you work with web applications on a a regular basis, at some point you're going to have to deal with gathering user input for storage in a database or for passing on via email. As you start to model more complex "problem domains, you will find that the forms that you require for gathering related input become much more complex.

For instance, let's take a simplistic example. A "Company" has many "Addresses" as shown by the diagram below.

How to Create a Blog from Scratch Using Ruby on Rails

Brief Overview of Ruby on Rails

Ruby on Rails is a framework for the Ruby language, which is used for rapid development of web applications. It does this by allowing you to concentrate on solving your clients’ problems and not getting caught up in building an infrastructure to support your clients problem.

Caching with Rails Part 1: Page Caching

alt text

Why do it?

There are three types of caching in Rails. In this tutorial we are going to concentrate on Page Caching. Page caching is the simplest and fastest form of caching in Rails. If you want to reduce the amount of times your Rails app hits the database then why not add some page caching.