■
rails3忘備録
・validatesのlength検証で検証内容inはwithinと書いてもOK
validates :bio, length: { within: 0..255 }
・alias_attributeは属性のaliasを作成
# authentication_token -> private_token(alias)
alias_attribute :private_token, :authentication_token
・よく利用する条件式にscopeで名前を付ける
# where(admin: true)にadminsという名前を付ける
scope :admins, where(admin: true)
# lambda式を使用すると名前付きscopeにパラメータを設定できる
scope :not_in_project, lambda { |project| where("id not in (:ids)",
ids: project.users.map(&:id) ) }