So you have duplicated routes in your resources? In today tutorial, I’ll show you how to DRY it up abit.
Liquid Templating Engine is an awesome technology and with the power of gem ‘liquid’, everybody can start using without much hassles. I saw many projects used this gem but sadly most of them are quite bad. In this tutorial, I’ll go through a bad example and show you how to refactor it.
Kamiari is an awesome that would do all heavy-lifting work if you want to do pagination. Yet Kaminari’s default layout does not fit well with Twitter Bootstrap pagination styling. In this tutorial, I’ll show you how to make Kaminari play well with Bootstrap v3.
Today I learned a nitfy trick from Jon Rowe on how to to create anonymous controller with rspec-rails for controller spec. This would aid testing action callbacks testing in controller.
One of the features I like about RubyMine is the gems dependency graph. This graps shows you all explicit/implicit dependencies of gems defined in your Gemfile. In this short tutorial, I’ll show how to generate this graph with Bundler.
Debugging integration is still a pain with headless driver like poltergeist. In this tutorial I’ll show you a good tip how to switch to selenium for debugging with Firefox.
Restore a DB dump with pg_restore is always a time-consuming process. However if you are using Postgres 8.4 or newer, you could speed it up easily by having multiple concurrent process do it for you.
In this short tutorial, I’ll show you how to update attributes for ActiveRecord model with:
- Validations are skipped.
- Callbacks are skipped.
updated_onare not updated.
Solutions for both Rails 3 and 4 are provided.
In my application, I bump to Exception when trying to delegate a method to an unfound ActiveRecord instance. This poses two issues for me:
- Hard to write test for you have to set up fixture/factory correctly
- Not a good user experience to see error on production
I tackle this with NullObject pattern to provide a graceful fallback.
Ruby gives us a nice human friendly
unless which is equivalent to negation of
if. Yet if we abuse using this method in a long complex statements, it could add more confusion for normal readers. In this article, I’ll give you one example to prove that you should not use
unless in a chain of conditions statement.