Articles

list remote branches

Sometimes you may need to figure out what branches exist on a remote repository so you can pull them down and check them out, merge them into your local branches, etc. If you’re using GitHub or gitweb to host your repository it’s usually easy to determine the branch names, but if you need to get them in general or for scripts it’s not exactly clear.

Simplifying Your Ruby Code

I used to write Ruby code like this a lot when I my brain was still half .NET.

def is_ready?
  if self.status > 3
    return true
  else
    return false
  end
end

I see this all the time on the Rails mailing list. Would you be surprised to know that you can write the same method this way:

def ready?
  self.status > 3
end

(I’d do away the the magic number “3” in favor of a constant, but I digress…)

Notice two things:

Load Fixtures into the Database

I was looking to load the fixtures into my database and it is very simple. Please look at the following code

1
rake spec:db:fixtures:load

Hope this helps somebody.

Cheers!

Pads

File Management

One of the most common features for web applications I’ve built over the last 4 years doing rails is file management. Users download file attachments in almost every web application I use. Thankfully rails has a really capable suite of file management tools, and there are several great plugins to handle some of the more mundane functionality you’d need.

Over the next month or so I’m going to cover the set of techniques I use when building file management solutions for my clients, and some really exciting up and coming solutions which solve the last of my annoyances.

easily fetching upstream changes

This tip comes from Dav Glass, whose work on YUI at GitHub requires him to bring in commits frequently. So, he’s created a helpful alias so he can merge in changes easily.

First off, he’s got a consistent naming scheme for his upstream remote:

git remote add upstream git://github.com/user/repo.git

When to use a bang (exclamation point) after Rails methods

-

Update:

A bang can used in the below ways, in order of my personal preference.

1) An active record method raises an error if the method does not do what it says it will. (e.g. create!)
2) An active record method saves the record or a method saves an object (e.g. strip!)
3) A method does something “extra”, like posts to someplace, or does some action.
4) other things

Ruby beginner tip: 2 key ways to write better methods

In development, few things make me cringe more than long methods. While they are faster, most people found that most of the time it’s just not worth the speed boost to write confusing code.

As people like Rein Henrichs have suggested, it should only take 3 seconds to figure out what a method does and only a few more to figure out how it works, at least in most cases in Ruby.

Long methods end up looking like this:

Fixture drama - in case you missed it

A long time ago Francis Hwang gave a presentation on ‘testing heresies’

One of his points was that he had experienced lots of bad things when trying to use fixtures, despite the fact that people encouraged you to use them.

Then recently Josh posted about how there are lots of choices when we setup new rails apps these days

In the comments, Francis reiterated his point.

Twitter API integration

How to use ExtJS Grid with Rails

railsonwave | Rails Fire

railsonwave