記事一覧
Rails 委譲(delegation) delegateについて
メソッドチェーンをたくさん書くことなく実装できる。
書き方の例は以下の通り。
delegate :method_name, to: :associtation
具体例は以下の通り。
Userモデルにログイン情報があり、関連する名前などはProfileモデルにあるとした場合。
delegate を使った場合
class User < ApplicationRecord has_one :p
メソッドチェーンをたくさん書くことなく実装できる。
書き方の例は以下の通り。
delegate :method_name, to: :associtation
具体例は以下の通り。
Userモデルにログイン情報があり、関連する名前などはProfileモデルにあるとした場合。
delegate を使った場合
class User < ApplicationRecord has_one :p