Tiramizoo Courier app
JavaScript Ruby
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Tiramizoo web app

Web application for customers to order deliveries and for various roles to sign up and maintain their profile and see stats.


  • Rails 3 (web app framework)
  • Mongoid 2 (Document oriented data store)
  • Cream (Roles etc.)
  • Devise (Authentication)
  • CanCan (Authorization)
  • Slim (Template system) https://github.com/stonean/slim

Haml to slim


Rails Wizard (tiramizoo)

Rails project creation wizard
Rails project

rails new APP_NAME -m http://railswizard.org/f8c0bcd629a3378401cb.rb -T -O -J

Mongo HQ

1. Confirm your MongoHQ database settings

In this example, we will assume your database is named fancy_pants and that the port that MongoHQ assigned to you when you created your database was Port 27021.

2. Make sure you have a MongoHQ database user set up on your database

You will need to have a database user set up on the database that you want to connect to. For this example, we will assume the username is admin and the password is sekret.

  MongoMapper.connection = Mongo::Connection.new('hatch.local.mongohq.com', 27021, { :logger => Rails.logger })
  MongoMapper.database = 'fancy_pants'
  MongoMapper.database.authenticate('admin', 'sekret')  

Mongo HQ connection

MongoHQ for Heroku users

  $ heroku addons:remove mongohq:free --app tiramizoo-beta
  $ heroku addons:add mongohq:free --app tiramizoo-beta  

Add remote connection on Mongo HQ

  $ heroku config --long --app tiramizoo-beta
  MONGOHQ_URL         => mongodb://heroku:0oymh4rkyqotfle3uuo4sw@flame.mongohq.com:27077/app399236  

Open Mongo HQ account and add a remote connection. Paste in the MongoHQ_URL from heroku log, and choose any database (that you already created on Mongo HQ)
Then the Web app on Heroku should be working!


Geokit and Rails
Google maps in a Rails app


See ApplicationController !!!

Every helper method dependent on url_for (e.g. helpers for named routes like root_path or root_url, resource routes like books_path or books_url, etc.) will now automatically include the locale in the query string, like this: http://localhost:3001/?locale=ja.

You may be satisfied with this. It does impact the readability of URLs, though, when the locale “hangs” at the end of every URL in your application. Moreover, from the architectural standpoint, locale is usually hierarchically above the other parts of the application domain: and URLs should reflect this.

You probably want URLs to look like this: www.example.com/en/books (which loads the English locale) and www.example.com/nl/books (which loads the Netherlands locale). This is achievable with the “over-riding default_url_options” strategy from above: you just have to set up your routes with path_prefix option in this way:

  1. config/routes.rb
  scope "/:locale" do
    resources :books

Now, when you call the books_path method you should get “/en/books” (for the default locale). An URL like http://localhost:3001/nl/books should load the Netherlands locale, then, and following calls to books_path should return “/nl/books” (because the locale changed).

If you don’t want to force the use of a locale in your routes you can use an optional path scope (donated by the use brackets) like so:

  1. config/routes.rb
  scope "(:locale)", :locale => /en|nl/ do
    resources :books

With this approach you will not get a Routing Error when accessing your resources such as http://localhost:3001/books without a locale. This is useful for when you want to use the default locale when one is not specified.

Of course, you need to take special care of the root URL (usually “homepage” or “dashboard”) of your application. An URL like http://localhost:3001/nl will not work automatically, because the root :to => “books#index” declaration in your routes.rb doesn’t take locale into account. (And rightly so: there’s only one “root” URL.)

You would probably need to map URLs like these:

  1. config/routes.rb

match '/:locale' => 'dashboard#index'

Do take special care about the order of your routes, so this route declaration does not “eat” other ones. (You may want to add it directly before the root :to declaration.)

Sven Fuchs’s routing_filter and Raul Murciano’s translate_routes. See also the page How to encode the current locale in the URL in the Rails i18n Wiki.

One source of client supplied information would be an Accept-Language HTTP header. People may set this in their browser or other clients (such as curl).

A trivial implementation of using an Accept-Language header would be:

  def set_locale
    logger.debug "* Accept-Language: #{request.env['HTTP_ACCEPT_LANGUAGE']}"
    I18n.locale = extract_locale_from_accept_language_header
    logger.debug "* Locale set to '#{I18n.locale}'"


  def extract_locale_from_accept_language_header

RSpec 2 setup

In Gemfile

gem “rspec-rails”, “>= 2.2.0”

Run generator

script/rails generate rspec:install

Test Devise with Rails 3 and RSpec2


Test Devise with Cucumber

Textmate bundles





Recaptcha with Devise


Get keys: http://www.google.com/recaptcha/whyrecaptcha


recaptcha_tags :public_key => ‘6Lc6BAAAAAAAAChqRbQZcn_yyyyyyyyyyyyyyyyy’

Later in a controller…

  verify_recaptcha :private_key => '6Lc6BAAAAAAAAKN3DRm6VA_xxxxxxxxxxxxxxxxx'  

Image upload



Form builder



Formtastic with mongoid tutorial


$ rails g formtastic:install

Generate form for existing model

rails g formtastic:form ExistingModelName [field:type field:type] --haml --partial


Embed one with fields for

Devise Authentication

Configure full Auth/Auth setup
Part 2


Customizing Devise


Compass (with blueprint?)


Lemonade (CSS Sprites)


Textmate bundle for SCSS

mkdir -p ~/Library/Application\ Support/TextMate/Bundles
cd ~/Library/Application\ Support/TextMate/Bundles
git clone git://github.com/kuroir/SCSS.tmbundle.git "SCSS.tmbundle"
gem install nokogiri
osascript -e 'tell app "TextMate" to reload bundles'  

Managing Styles with Sass on Heroku

CSS Tricks (1 of 2): First, Get Down with the OOP
CSS Tricks (2 of 2): Using Rails to Manage Styles

Blueprint CSS framework


Heroku setup

Setup Heroku for Rails 3 and ruby 1.9.2

$ heroku create tiramizoo-test —stack bamboo-ree-1.9.2

Google Maps

IP to country geocoding


- Distance calculations, for both flat and spherical environments. For example, given the location of two points on the earth, you can calculate the miles/Km between them.

- IP-based location lookup utilizing hostip.info. Provide an IP address, and get city name and latitude/longitude in return

- A before_filter helper to geocoder the user’s location based on IP address, and retain the location in a cookie.

- Geocoding from multiple providers. It provides a fail-over mechanism, in case your input fails to geocode in one service. Geocoding is provided buy the Geokit gem, which you must have installed

Bhm plugin

<%= draw_map_of Location.new(“My House”, 12.345, 56.789) %>


API Keys

  • localhost:3000 – ABQIAAAAUzkItq4p7LYo2YIR_gtjpRTJQa0g3IQ9GZqIMmInSLzwtGDKaBSzEc8_FNxIfQLkpKOh9R4JB87Rig
  • tiramizoo-beta.heroku.com – ABQIAAAAUzkItq4p7LYo2YIR_gtjpRScPhHhTyTGueeJo8sXYsnV4VMnTBT2MqnfY3aPuvIhBjwfhTZoE2EtZA

Google Maps with Rails – How to

How to

Google map directions


Geo auto-completion

Geo autocomplete

Geocode libraries


  g = Geocode.new_geocoder :google, {:google_api_key => "abcd1234_SAMPLE_GOOGLE_API_KEY_etc"}
  result1 = g.geocode "1600 Amphitheatre Parkway, Mountain View, CA"
  result2 = g.reverse_geocode "37.421759,-122.08437"  


  require 'rubygems'
  require 'graticule'
  geocoder = Graticule.service(:google).new "api_key"
  location = geocoder.locate "61 East 9th Street, Holland, MI"
  p "zip: #{location.zip}"

Travel Modes

By default, directions are assumed to be driving directions though you may request other modes of travel by passing a GTravelMode when calling the Directions.load() method. The following travel modes are supported:

* G_TRAVEL_MODE_DRIVING indicates standard driving directions using the road network

  • G_TRAVEL_MODE_WALKING requests walking directions via pedestrian paths & sidewalks (where available.)

Note: Walking directions may sometimes not include clear pedestrian paths, so walking directions are only supported if you have supplied a in the GDirections constructor; this is used to display a warning to the user in the returned turn-by-turn textual directions. If you do not have such a , a request for walking directions will return an error.

Handling Returned Directions

If the GDirections object was constructed with a supplied GMap2 object, then the returned directions will contain a polyline overlay. If the GDirections object was constructed with a supplied element, then the returned directions will contain a GRoute object, containing a set of GStep objects. (If the directions consist of multi-point directions, the returned directions will contain multiple GRoute objects, each consisting of a series of GStep objects.)
Note that the directions object is not populated with this return information immediately. For this reason, the GDirections object defines a “load” event which you can intercept to determine this state.

Once directions are returned, by default, the map will display a polyline showing the route, while textual directions will display within the supplied for that purpose. The GDirections object will also internally store results which you can retrieve using GDirections.getPolyline() and/or GDirections.getRoute(i:Number) methods. Steps within a route can be retrieved using the GRoute.getStep(i:Number) method and the HTML summary of that step can be retrieved using GStep.getDescriptionHtml(). (See Routes and Steps below.)

The GDirections object also fires three events which you can intercept:

* “load”: This event is triggered when a directions result successfully returns, but before any overlay elements are added to the map/panel.
* “addoverlay”: This event is triggered after the polyline and/or textual directions components are added to the map and/or DIV elements.

Routes and Steps

The GDirections object also supports multi-point directions, which can be constructed using the GDirections.loadFromWaypoints() method. This method takes an array of textual input addresses or textual lat/lon points. Each separate waypoint is computed as a separate route and returned in a separate GRoute object, each of which contains a series of GStep objects.

GRoute objects store the number of steps (of type GStep for that route, the starting and ending geocode for that route, and other computed information such as distance, duration, and exact lat/lon of the endpoint (which may be different than the ending geocode if the geocode does not lie on a road segment). Each GStep object as well contains the description for that text (e.g. “Merge onto US-101 S via the ramp to San Jose”) plus computed information including the distance, duration, and exact lat/lon as well.


directions simple code example


2010 Tiramizoo.com