Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A simple ruby solution to displaying addresses.

tag: v1.1.2

Fetching latest commit…


Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 rails Switch to jeweler from hoe June 28, 2009
Octocat-spinner-32 test Switch to jeweler from hoe June 28, 2009
Octocat-spinner-32 .gitignore Release v1.1.1 May 14, 2009
Octocat-spinner-32 CHANGELOG.rdoc
Octocat-spinner-32 LICENSE Switch to jeweler from hoe June 28, 2009
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
Octocat-spinner-32 init.rb Release v1.1.0 May 14, 2009

Address Logic

This is a simple library that takes away the annoyances of displaying addresses in a view. Since various parts of an address can sometimes be optional, such as “street2”, displaying addresses was not fun:

# some HAML view
= address.street1
- if !address.street2.blank?
  = address.street2
== #{}, #{address.state} #{}

That's just ugly. Instead, you can do this with Address Logic:

= address.address_parts.join("<br />")

Or, what about a single line address?

= address.address_parts.join(", ")

Maybe you only want city and state:

= address.address_parts(:only => [:city, :state]).join(", ")

Granted the above is probably easier without using AddressLogic, but it will purge any blank items in the address, so if city or state are optional then it would be cleaner to use AddressLogic.

Install and use

As a gem:

$ sudo gem install addresslogic

Or as a plugin

$ sudo script/plugin install git://

Then just include the AddressLogic module into any class of your choice. All that it assumes is that you have the street1, street2, city, state, zip, country (optional) methods.

class Address

You can specify the fields too:

class Address
  apply_addresslogic :fields => [:street1, :street2, :city, [:state, :zip], :country]

Helpful links

* Documentation:

Copyright © 2009 Ben Johnson of [Binary Logic](, released under the MIT license

Something went wrong with that request. Please try again.