You should always commit Gemfile.lock and schema.rb

One of common mistakes I see with new (and some experienced) Ruby on Rails programmers is that they do not commit Gemfile.lock and schema.rb very often to source control version such as Git or SVN. I personally think that it is generally bad practices and we should commit…

How to convert HTML views into PDF in Rails

One of the most popular programs to convert HTML to PDF is wkhtmltopdf. And in this post, I am going to show you how to use wicked_pdf gem to quickly export your views into PDF using this program. First, you would need to install wkhtmltopdf program in your platform…

Polymorphic Routes in Rails

In Rails, you can define a model as polymorphic like the following: class Post has_many :comments, as: :commentable end class NewsItem has_many :comments, as: :commentable end class Comment belongs_to :commentable, polymorphic: true end And I believe your resources would look like this: resources :posts resources :comments end…

Using serialize option in Ruby on Rails

In this post, I am going to show you how to make use of serialize option in Ruby on Rails so that you can store information in your database more efficiently. First of all, have you ever been in a situation which you want to store an array or a…

Get width/height of invisible DOM elements

When working with elements in jQuery, you might need to get width/height of certain invisible DOM elements. By default, jQuery would return 0 in this case because it can not calculate the actual height() of that element. In order to solve this problem, I take advantage of jquery.actual…

Long-polling with Puma, Rails 4 and Server Sent Events

In this post, I am going to show you how to create a long polling server with Puma, ActionController::Live in Rails 4 and Server Side Events in modern browsers. Why there is another post when there are already many of them on the Internet? It is just because I…

How to install wkhtmltopdf on OSX (August 2014)?

Today, when trying to install wkhtmltopdf package to my Mac via brew, I got the following error: Error: No available formula for wkhtmltopdf I have searched on the Internet and realized that this package was removed from brew. But you still can install it via homebrew-boneyard - Archive of formula…

How to configure SSH for multiple Github accounts?

Note: I only refer to Github in this post but this method can be applied to any Git servers (such as Bitbucket, Heroku, etc) If you work with Github for a while, you would realize that there are two kinds of links for you to work the Git repos: HTTPS…