RSS ? Recent Blog Posts

Blogs » Ruby on Rails
 

Get on Track

: Ruby on Rails Blog

The Rails Myths

by Myles Eftos

We’ve all heard the arguments that Rails doesn’t scale, it’s hard to deploy or that it will explode in your hands at any given moment. For those of us that use Rails on a daily basis, we know that those are just myths, though.

 

Timezones in Rails 2.1

by Myles Eftos

It isn’t particularly surprising that timezone support is a pretty important component of web applications, as the web really is a global medium. If you are building an application that has to deal with times, timezone support can make your life vastly easier.

 

Let’s get meta: missing method

by Myles Eftos

If you are coming from PHP, or C# you might not find yourself thinking in terms of meta programming – although both languages can do meta programming, it doesn’t seem to be heavily used. This isn’t the case in Ruby – quite the opposite – meta programming is a HUGE part of Ruby.

So what is meta programming? It is basically a way of modifying programs dynamically, like adding or changing methods AFTER the program has started running (or at runtime as we like to call it).

A great example of this is the find_by_* methods in rails. If you have a model called “User” that has a column called “age” you can search your records by age using the magic method User.find_by_age. This is accomplished using the method_missing method.

If you call a method that doesn’t exist, Ruby will call the method_missing method, and pass the name of the method and any arguments you supplied, which means you can dynamically handle the method.

class MyClass
def find(name, value)
puts “You want results from #{name} with a value of #{value}”
end

def method_missing(id, *args)
return self.find(Regexp.last_match(1), args[0]) if id.id2name =~ /find_by_(.+)/

 

This week in Rails. 30 June-04 July

by Myles Eftos

I admit, Ruby’s Interpreter isn’t the fastest one around, and whilst there are alternative interpreters that are promising blazing speeds, there are thankfully some things you can do to speed up what we already have. igvita.com has a list of 6 Optimisation Tips for the Ruby MRI. There are a couple of surprising ones in there.

Whilst on the topic of speed, using static pages for any pages that need to be, well, static is always a good idea. Railscast has a new screen cast entitles Semi-Static Pages.

If are a Capistrano n00b, or you have been meaning to have a look at it, why don’t you join the Online Capistrano Tutorial Session, held via Campfire next week. It will be on July 15 at 7pm MDT (what ever timezone that is) and will be given by Rails core-contributer Jamis Buck. I’m personally intrigued as to how this will work, so I might even log in to check it out.

Until next time!

 

This week in Rails – 09/06 to 13/06

by Myles Eftos

It seems that testing has been on the flavour of the week, which is apt really as I myself have been playing with RSpec a lot lately (Blog post forthcoming, once I finish up one of the projects that has been using said testing framework).

Simon Harris from My hovercraft is full of eels describes a simple way to break up you tests into DRY, manageable chunks: http://www.redhillconsulting.com.au/blogs/simon/archives/000429.html

Ben Mabey shows you how to use Macros in RSpec, using Shouda. Macros are as old as the hills, but can be really handy to organise many tasks simply: http://www.benmabey.com/2008/06/08/writing-macros-in-rspec/

Michael Ivey reminds us why we should use tests. Not only are they a nice support net, but they encourage us to write better code. It’s like extreme programming without the other programmer: http://gweezlebur.com/2008/6/13/tests-make-you-write-better-code

Outside of the testing arena, a new version of Capistrano — possibly the coolest tool for Ruby — has been released. If you haven’t had a play with Capistrano yet, go and install it and try it out.

And finally for this week, if you have ever been perplexed about whether pieces of code belong in the Model, View or Controller, Starjuice has an …

 

This week in Rails – new release edition

by Myles Eftos

Rails 2.1 release

This week saw the release of of version 2.1 for Ruby on Rails. You can see the announcement on the official Rails blog.The new major features are:

  • Time zones (by Geoff Buesing)
  • Dirty tracking
  • Gem Dependencies:
  • Named scope (by Nick Kallen)
  • UTC-based migrations
  • Better caching

IronRuby runs Rails

The IronRuby team also announced this week that they managed to get a “Hello World” example running on an unmodified Rails stack. Although it’s not yet ready for prime time, we are one step closer to being able to run Rails on .NET. See the announcement on Jon Lam’s blog.

RailsConf

RailsConf was held in Portand this week. Unfortunately a trip to the US was stretching the budget a little, so if you were like me and unable to make it, check out Gregg Pollack’s video compilation of a number of interviews he had with some of the speakers. RailsConf in 36 Minutes.

Until next time Railers!

 

Did Rails Sink Twitter?

by Kevin Yank

Twitter is arguably the most heavily used Ruby on Rails application in the world. Almost since its inception, Twitter has fostered a wildly passionate cult following. Also from the beginning, Twitter has suffered from chronic outages under that load.

In the past month, record downtime has prompted fresh outcry within its ever-growing user base. This, along with increased attention from mainstream media has forced Twitter to publicly acknowledge these issues, and to reveal a few details about the source of these problems.

Though there has been much speculation about the source of Twitter’s performance issues, the closest we have had to a real peek under the hood has been this Twitter Developer Blog post:

Twitter is, fundamentally, a messaging system. Twitter was not architected as a messaging system, however. For expediency’s sake, Twitter was built with technologies and practices that are more appropriate to a content management system.

But wait, what exactly do they mean by “technologies and practices”? Could they mean Ruby on Rails?

Twitter and the Curse of the Framework

Ruby on Rails is a Model-View-Controller (MVC) framework. To build an application in Rails, you start by defining a collection of objects that model the things your application will do, then …

 

Simply Rails 2: Your Rails 2 beginners book

by Shayne Tilley

The first edition was touted as the ultimate rails beginners book and read by 10’s of thousands of people. I’m pleased to announce a 2nd edition to Patrick Lenz’s brilliant book…

It’s called Simply Rails 2 and is available for purchase right now in PDF or Printed format at sitepoint.com.

Grab the printed version for just $39.95 or the PDF version for just $29.95.

With Simply Rails 2 you’ll learn how to build bulletproof Web applications from scratch, with more features using less code.

Patrick’s updated the entire book to take advantage of all the new Rails 2 features. It’s the only beginner’s book we know that’s Rails 2 ready…

Inside the book you’ll learn how to:

- Build and deploy your own Rails web application.
- Reap the benefits of using best-practice MVC architecture.
- Use Rails’s Ajax features to create slick interfaces.
- Interact with databases easily using ActiveRecord.
- Add the magic of REST to your apps with Rails Resources.
- Use plugins to enhance your applications easily.

Simply Rails 2 will show you that there is a simple and easy way to build web 2.0 applications.

Grab yourself a copy today!

 

Rubinius runs Rails

by Myles Eftos

There was a short note today, that the Rubinius development team has successfully run Rails on their virtual machine. Although isn’t anywhere new production ready yet, it is a significant step forward in getting a faster Rails.

I covered some of the alternate Ruby implementations previously.

Congratulations to the team!

 

Rails 2.1 release candidate 1 is on its way

by Myles Eftos

Word out on the wire is that Rails 2.1 RC1 has been tagged in the repository, so the gems should be available shortly. Being a point release, the changes aren’t major – mainly bug fixes and some performance improvements, but there are still some new features that will make it worth a look.

Updated timezone support

Timezones will finally become a first class citizen in Rails. You will be able to set the timezone, and all subsequent time calls will be with in that zone.

Time.zone = “Australia/Perth”
Time.zone.now # will return something like Wed, 24 May 2008 22:56:00 WST +08:00

Better Gem dependencies

If you rely on gems in any of your projects (and why wouldn’t you? Code re-use and all that), you may have come across the pain of gem versioning. Rails 2.1 will allow you to stipulate what versions of each gem you need.

config.gem “chronic”, :version => ‘0.2.3′

It also adds a rake task that will automatically install the right gems for you.

rake gems:unpack

Improved caching

Previously, the only caching options Rails developers had was based around file fragments, which is fine for single server setups – but scaling that up to multiple servers could cause synchronisation issues, causing your cache to go stale. …

 

Sponsored Links

SitePoint Marketplace

Buy and sell Websites, templates, domain names, hosting, graphics and more.

Follow SitePoint on...