Advantages of choosing Ruby on Rails for your Startup !

Posted on by tkwong

This was a post that was long pending that we wanted to write but somehow assumed that all would know fair and square. Anyway we are putting it in words here for the benefit of the entrepreneurs and the startup community . Ruby on Rails has come a long way from its inception and with Rails 3 we can clearly define the value differentiator of Ruby on Rails in comparison with conventional technologies.

1. With Ruby on Rails a Quick transformation of concepts to code is possible.
2. Rapid framework building capable. Building the basic product can be very fast on ROR
3. Incremental integration is possible as there is a structured framework
4. Testing of code of errors is integrated as part of the process.
5. Possible to reduce your lead time from configuration setting to application deployment by more than 40%.
6. Build on ROR is lean and mean very compatible for mobile devices of the future.
7. Your product is future ready for emerging trends to build mobile solutions and cloud models.
8. Capitalise on the benefits of Opensource with strong online community presence that constantly refines code.
9. ROR is best suited for BDD and Agile environment where value creation is the top priority for a project

Ray Lee liked this post

Rails 3.1 include CoffeeScript, jQuery, Sass as default

Posted on by tkwong

This gallery contains 3 photos.

Yes, the coming Rails 3.1 is going to be bring new library as default: CoffeeScript, jQuery, and Sass.

In true Ruby and Rails style, there’s been a little controversy over today’s CoffeeScript and Sass news. While the jQuery migration was pretty much accepted due to Prototype’s position six feet under, plenty of developers are familiar with JavaScript and either feel slighted by CoffeeScript’s inclusion as a default or are concerned that it’ll act as a barrier for newcomers to Rails in future.

Given that you can “opt out” of having CoffeeScript and Sass included in your Rails projects by making a minor change to your Gemfile, this faux-controversy is nowhere near as interesting to me as the legitimate RSpec vs Test::Unit debate that DHH kicked off.

However, if you want to grab some popcorn and enjoy the bullshit, the comments on this GitHub commit page are epic. People have even gone so far to produce graphics to express their opinions. Rock and roll. There’s also a significant level of pie-slinging going on on Twitter too. lets quickly go through the details now.

jQuery – Trivial

A lot of Rails applications lean on JavaScript to provide client-side and AJAX functionality. Till now, the Prototype library had been included in Rails by default as a way to make various things easier to achieve across different browsers, but jQuery has become significantly more popular over the last few years.

Given this, DHH’s announcement passed with little controversy since Rails developers had become used to using jQuery and installing the jquery-rails gem anyway. A good move and a progression with the times – awesome.

CoffeeScript – JavaScript, Improved

CoffeeScipt, which may be new to all. From CoffeeScript : CoffeeScript is a little language that compiles into JavaScript. If started life as a Ruby project that converted a cleaner, JavaScript-esque language into JavaScript. CoffeeScript’s syntax enables you to write JavaScript in a cleaner and, often, more logical way.

Sass – CSS (yes) – HAML – HTML (no)

Sass is to CSS as CoffeeScript is to JavaScript, though to a less extreme level. In its modern form, Sass looks just like CSS but adds support for things like variables, functions, nesting, and similar useful features. Crucially, Sass is just a superset of CSS so you can still use regular CSS with Sass and it’ll Just Work™. You can then learn new features one by one and start using them as you like (I must admit, I’m a massive fan of Sass and I mostly stick to the variables and nesting features).


How to Play with Rails 3.1, CoffeeScript and All That Jazz Right Now

Upgrade redmine from 0.9.x stable to 1.1 stable

Posted on by tkwong

Redmine makes it pretty easy and smooth for us to upgrade itself. Here is a link for general upgrade from Redmine: RedmineUpgrade.

In 1.1 stable version, there are some good new features that 0.9.3 doesn’t have, i,e: the Gantt chart , the Calendar, and the new concept of Subtasks/Parent tasks and so on. For more detailed features of newest redmine, you may visit: Features.

If you have redmine running at an old version like 0.9.x, and feel strongly like upgrading redmine to the latest stable version, you may try this simplest solution:

  1. Backup files/ and database, very important!
  2. svn switch
  3. rake db:migrate RAILS_ENV=production

Note that Steps 2 and 3 must be done in your existing redmine root.

After you have completed the above three steps, just restart your application and you will see the new exciting Redmine, hooray!

Just in case of you are not familiar with linux, let me explain more:
1. How to backup files?

cp -r your_redmine_root/files your_backup_destination/files

2. How to backup database?

mysqldump -u username -p password redmine_db_name <  your_backup_destination/redmine_db_backup.sql

Rails SEO pack: 5 plugins to optimize your site

Posted on by tkwong

Here I am going to share some insights on getting your Ruby on Rails site to perform better in search engines, popularly called SEO or Search Engine Optimization.

We are going to use these five Rails plugins:

  1. Headliner for titles
  2. Metamagic for meta tags
  3. Gretel for breadcrumbs
  4. FriendlyId for friendly URLs
  5. Dynamic Sitemaps for sitemaps

1. Titles using Headliner

Headliner is a Ruby on Rails plugin for creating titles in a <title> tag. The plugin makes it easy to define your titles without having to define it in several places.

Titles are important in your SEO pack because they tell search engine users what content is in your individual pages.

In your application.html.erb:

<%= title :site => "My Awesome Site",
:separator => "—",
:reverse => true %>

In your view:

<h1><%= title "Contact info" %></h1>

Would generate the following:

<title>Contact info — My Awesome Site</title>

2. Meta tags using Metamagic

Metamagic is a Ruby on Rails plugin for generating meta tags.

Despite what you may have heard, meta tags are still important in your SEO pack, especially the description meta tag which Google uses in addition to the page content to both find and display your site.

In your application.html.erb:

<%= metamagic :title => @title %>

(the :title => @title part is to automatically retrieve the title from the above mentioned Headliner plugin.)

In your view:

<% meta :description => "This is my page description.",
:keywords => "one, two, three" %>

Would generate the following:

<meta name="title" content="Page title set using Headliner" />
<meta name="description" content="This is my page description." />
<meta name="keywords" content="one, two, three" />

3. Breadcrumbs using Gretel

Gretel is a Ruby on Rails plugin for generating breadcrumbs.

Breadcrumbs are important in your SEO pack as they tell both users and search engines the location or “path” to your pages. Google will also often display the breadcrumb instead of the page URL.

In your application.html.erb:

<div id="breadcrumb">
<%= breadcrumb :pretext => "You are here:",
:separator => "›",
:autoroot => true,
:show_root_alone => false,
:link_last => false %>
In config/initializers/breadcrumbs.rb:

Gretel::Crumbs.layout do
crumb :root do
link "Home", root_path
crumb :articles do
link "Articles", articles_path
crumb :article do |article|
link article.title, article_path(article)
parent :articles

In your controller:

def show
@article = Article.find(params[:id])

In your view:

<% breacrumb :article, @article %>

Would generate a breadcrumb like this:

<div id="breadcrumb">
You are here: <a href="/">Home</a> › <a href="/articles">Articles</a> › My Article

4. Friendly URLs using FriendlyId

FriendlyId is a Ruby on Rails plugin for generating friendly URLs.

Friendly URLs are important in your SEO pack as they tell users and search engines what lies beneath the URL, e.g. /articles/34 becomes/articles/my-awesome-article.

In your model:

class Article < ActiveRecord::Base
has_friendly_id :title,
:use_slug => true,
:approximate_ascii => true

In your controller:

def create
@article = Article.create(:title => "My awesome article")
redirect_to article_path(@article) # => /articles/my-awesome-article

5. Sitemaps using Dynamic Sitemaps

Dynamic Sitemaps is a Ruby on Rails plugin for generating sitemaps in XML format specification.

Sitemaps are important in your SEO pack because they enable search engine crawlers to find all of your pages.

In config/initializers/sitemap.rb:

Sitemap::Map.draw do
url root_url, :last_mod =>, :change_freq => 'daily', :priority => 1
url about_url, :change_freq => 'monthly', :priority => 0.5
url contact_url, :change_freq => 'monthly', :priority => 0.5
url terms_url, :change_freq => 'monthly', :priority => 0.5
autogenerate :articles, :last_mod => :updated_at, :change_freq => 'weekly', :priority => 0.8

Would generate a sitemap like this:

<urlset xmlns="">


I hope this short guide will be of great use when you’re optimizing your page for search engines. If you have further tips or suggestions, please write a comment below.


Time Zones Problem

Posted on by tkwong

Time functions in Rails at some points rather shaky. So you would expect and 0.seconds.ago equal. That is not so: => Thu May 28 23:28:37 +0200 2009 >> 0.seconds.ago => Thu, 28 May 2009 23:28:42 CEST +02:00

Closer inspection shows that a normal Ruby Time instance, while 0.seconds.ago an ActiveSupport::TimeWithZone object.

And that is quite a difference! In this code example:

>> => "2009-05-28 23:33:08" >> 0.seconds.ago.to_s(:db) => "2009-05-28 21:33:16"

The to_s (: db) method is used to find queries and named scopes, and the above difference is that the use of , Time.parse and Time.atinadvisable when the database as a parameter can be used. Rails convertsTime instances will in TimeWithZone items from ActiveRecord attributes.Alternatively etc. used.
In short: u.published_at = works fine, but when you are in your environment.rb you are a local time zone, this is wrong in Rails 2.3.2:

named_scope :begun, proc{{:conditions => ['started_at < ?',]}}