Now and then I get question from people should they use class method or the scope DSL for ActiveRecord scope. At first I thought they are the same but in fact there are minor differences.
By default, SQL
ADD COLUMN would add new column to the tail of columns. What if you
want to add a new column and append this new column after an existing column? Read on
and I’ll show you how to do that with Rails in MySQL
So you search for how to moneykey-patch a class in Ruby? Read on, I’ll show you how.
Hash is beautiful. It is one of many things why I love Ruby. As you might have known, Hash is identified by a key, this key could be either a String or a Symbol. For most of cases, people tend to go for symbol because it would take up less memory (though it might come with a side effect that is Symbol is not GC-colletable (Ruby 2.2.0 does clean it up though)).
There are access usecases that requires our hash key to be interchangable between String and Symbol key. For example, web application request parameter processing.
We could typecast the key to either String or Symbol but it would soon emerge an annoying pattern. Instead, with the help of ActiveSupport, you can create a hash with no differences if accessing using String or Symbol key. Introducing ActiveSupport::HashWithIndifferentAccess.
One of the hot thing in Rails 4.2 is the brand new ActiveJob gem, this gem consolidate the API for background job gems on the market such as DelayedJob, Resque, etc. Today I am going to guide you through how to integrate Sidekiq with ActiveJob, and you will learn:
- Set up Sidekiq adapter for ActiveJob
- Basic of ActiveJob class
- Advanced usage of multiple queues
- ActiveJob callback
- ActiveJob exception catch
- ActiveJob mailer API
For whom who might have not heard of Silicon Straits Saigon (SSS), this company is one cool company in Vietnam with strong focus in tech such as iOS and Web. When I use the word cool, I did not mean it before I touch base with their hiring challenge.
SSS is known to have a quite unique way to challenge potential employees. They give you a very cryptic page http://hiring.siliconstraits.vn and asks you to hack them.
Well, today I am going to show you how to solve this problem step by step. I hope Mr. An (Director of SSS) won’t hate me for this.
Spoiler alert! Go give the challange a go yourself before reading!
There are many people who asked me about the differences between
git rebase vs
Read on if you want to know :-)
If your ActiveRecord models happen to have default ordering scope, you could override
this ordering scope in queries by using
Rails comes with a powerful and convenient
serialize method that would do the serialization/deserializtion
for a specify column of an ActiveRecord model. In today tutorial, I’ll walk you through on how to write a
custom serializer that would encrypt/decrypt your serialized value for extra security.
Rails is all about Convention over Configuration, this includes the DB primary key,
which is always set to be
id column. What if you want to use different column
as your primary key? Read on and I’ll show you how.