0001
Limit vs Take
- take return array
- limit return ActiveRecord relation which can used to chain
How to Use CSV in ruby for write to file
require 'csv'
HEADERS = ['x', 'y', 'z']
CSV.open('file', 'w', headers: HEADERS) do |csv|
csv << [x, y, z]
end
# or
test = CSV.open('file', 'w', headers: HEADERS)
test.puts [x, y, x]
test.close
present? vs blank? (nil?, empty?)
- nil? 単純にnilか
- empty? は[], {}, '', ""を判断 not nil
- blank?は nil? + blank?
- present?は blank?の逆、でもonly for ruby
0003
Rails単一継承(STI)とサブdir構成を実現する方法
方法1
app/models/parent.rb
app/models/parent/mother.rb
app/models/parent/father.rb
class Parent < ApplicationRecord; end
class Parent::Mother < Parent; end
class Parent::Father < Parent; end
# rails consoleで検索するには
Parent::Mother.all
Parent.where(type: 'Parent::Mother')
方法2
# add this to config/application.rb
config.autoload_paths += Dir[Rails.root.join('app', 'models', 'parent')]
app/models/parent.rb
app/models/parent/mother.rb
app/models/parent/father.rb
class Parent < ApplicationRecord; end
class Mother < Parent; end
class Father < Parent; end
# rails consoleで検索するには
Mother.all
Mother.where()
0004
development method
- DDD develop
- TDD (test-driven)
FDD ()