Using has_many :through for nested has_many relations in Rails

has_many :through is a useful association type of Rails. It's mostly popular and often used as a join model for many-to-many relations.


However, has_many :through is more than a simple join model, because it conducts INNER JOIN(s) on related models. We can also take the advantage of this beha...

Continue reading

Running Rake Tasks in a Loop

Rake tasks in a loop, will only executed once when they are not re-enabled. Take a look to this example:

namespace :yoksis do
  desc 'fetches all references'
  task :references do
    mapping = {
      get_instruction_language: 'UnitInstructionLanguage',
      get_instruction_type: 'UnitInstructionType'

    mapping.each do |action, klass|
      Rake::Task['yoksis:reference'].invoke(action, klass)

  desc 'fetch an individual reference'
  task :reference, %i[soap_method klass] => [:environment] do |_, args|
    puts args[:soap_method]
    puts args[:klass]

When you run the yoksis:references task, it will only print out {get_instruction_language: 'UnitInstructionLanguage'} and will skip the second item of the mapping hash.

Continue reading
Date: | Tags: ruby, ruby on rails, rake, rake in loop | Categories: tech, ruby, ruby on rails

Boolean Type Words in YAML

YAML is a widely used data serialization language. In any software development project, or a random dev-ops task you can come across with YAML. For example Ruby on Rails uses YAML for fixtures, configuration files and localization. CI/CD tools such as CircleCI and Travis also use YAML for configuration. If you ever experienced a strange behaviour with YAML, you may have used the reserved words of YAML. YAML reserves some words such as 'yes', 'no', 'y', 'n', 'off', 'on', etc. for boolean type. For example:

    turkish: evet
    german: ja
    english: yes
    turkish: hayır
    german: nein
    english: no

will be interpreted as:

    turkish: evet
    english: true
    turkish: hayır
    english: false
Continue reading
Date: | Tags: yaml, yaml reserved words, yaml boolean type | Categories: tech, ruby, ruby on rails

Rails Instantiated Fixtures

Here we have sample Ruby on Rails fixture file:


  name: sample
  text_message: hello
  phone_number: 0555444332211
  first_name: foo
  last_name: bar

There are two popular ways to use fixtures in your Rails tests. The first one is directly calling the name of fixture file followed by a symbol stating the name of any individual fixture, ie:

class NewsletterTest < ActiveSupport::TestCase
  test 'a sample test' do
    assert newsletters(:tenant_newsletter).valid?
Continue reading

Find the Real Names of Telegram Users Just with a Phone Number

I follow and admire Telegram project since their first release. If you haven't already heard about Telegram, it is a messaging platform with tons of useful privacy and security features, and offered completely for free. Telegram project still misses some key features such as an open source codebase and organization level Github repository, to gain my full adoption, but I trust their guarantee for making the source code open in the future.

Yesterday I noticed an interesting behavior of Telegram, and perhaps a potential issue to concern about your privacy. During an update on my contact list, I accidentally noticed that I could retrieve the real names of random people just with mobile numbers.

TL;DR: If you ever created a Telegram account with your real name, anyone with your phone number can reveal it. Or anyone generating a random list of phone numbers can match which phone number belongs to whom. In reverse, you can find the real names of prank callers, or just random people.

Continue reading