rails

Using PhantomJS to serve HTML content of Single-page App

One big drawback of Single-page application is the ability to fully support SEO as traditional sites. The reason is because in a single-page application we often use a technique called lazy-rendering, in which the real content is not rendered from the server but only the basic layout is returned. Many…

Git rebase or Git pull?

A few days ago, one member in my lab and I were about to finish a project together. We also used git server for sharing code and collaborate. However, when I used combination of git fetch, git stash, git rebase and git stash apply to fetch new code, he said…

Tips for debugging your production web app

Running the app in development or staging environment is a lot easier than production environment. There are so many unexpected factors which make your application unstable in production, such as a high number of concurrent users, lots of queries to database, etc. And when something go wrong on production app,…

Understanding Locking in Rails ActiveRecord

Data consistency is very important in many applications, especially for application related to finance, banking, etc. A small error could become a tragedy if we do not treat it seriously. This time, I am going to talk a bit about Locking and how you can use it to protect data…

Useful NGINX configurations for Rails app

Nginx is now becoming the favorable choice of many Rails developers when deploying the Rails app. It is lightweight, fast and has almost everything we need. In this post, I am going to introduce a few useful configs which I often use in Rails app. 1. Redirect www to non-www…

Skip ActiveRecord callbacks

Callbacks are great and many business rules are often implemented in those callbacks to maintain data consistency and perform useful actions in app. As you might know, we can define several kinds of callbacks in ActiveRecord model, refer to the following guide for more detailed information: http://guides.rubyonrails.org/…

Gem Idol: Friendly Id

This week, I would like to introduce a gem which is being used in almost every project I have been working on. And it becomes more important for us nowadays because everyone want their website to be SEO efficiently. Link: https://github.com/norman/friendly_id Developed by: Norman Clarke…

Custom dialog for data-confirm in Rails

Every Rails developers might be already familiar with data-confirm attribute for a link. It is used to ask for user confirmation before executing the action on behalf of user. Here is one example <%= link_to "Delete", post_path(post), method: :delete, confirm: "Are you sure?" %> The generated link…

Gem Idol: Figaro

Today, I really want to start something different which I believe would be very helpful to new Rails developers. I remember the time when I first came to Rails world, I was impressed with its amazing community and gem ocean. I could find almost every thing I needed which has…

Running Faye server on AWS ElasticBeanstalk with Load Balancer

One of the amazing features you want to build in your application is the ability to deliver content to users in real-time without requiring them to refresh the browsers. You can achieve this by sending requests in fixed interval to the server to get changes or you can have a…

Several tools to monitor your Rails application

After your Rails application is deployed to server, there would be tons of things could happen to your app which you have never expected when running the app in your local environment. In that case, you definitely want to have a tool to support you monitoring the application and quickly…

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…