Tbpgr Blog

Employee Experience Engineer tbpgr(てぃーびー) のブログ

ActiveSupport | String#foreign_key

概要

String#foreign_key

詳細

String#foreign_key について

String#foreign_key

文字列から外部キー用の文字列を取得する。

サンプル

# encoding: utf-8
require 'active_support/core_ext/string/inflections'
require 'tbpgr_utils'

bulk_puts_eval binding, <<-EOS
'Person'.foreign_key
'SomeModule::Person'.foreign_key
'HugePerson'.foreign_key
EOS

__END__
・下記はTbpgrUtils gemの機能
bulk_puts_eval

https://rubygems.org/gems/tbpgr_utils
https://github.com/tbpgr/tbpgr_utils

出力

'Person'.foreign_key # => "person_id"
'SomeModule::Person'.foreign_key # => "person_id"
'HugePerson'.foreign_key # => "huge_person_id"