Rails アプリには、ユーザーが支払うことができるイベントがいくつかあります。現在のユーザーに応じてイベント価格を変更できるようにする必要があります。
* モデル内の current_user へのアクセスに関するトピックがすでにたくさんあることは知っていますが、私が探しているものではありません。
私は次の2つのモデルを持っています(本当に単純化されています)。チェックアウトは、イベントに関連付けられたすべての支払いを管理しています (実際のアプリでは、イベントとのポリモーフィックな関連付けがあるため、別のモデルでそれが必要でした)。
class Event < ActiveRecord::Base
  attr_accessible :ticket_price, :checkout
  has_one :checkout
  checkout_price
    # Here I'd like to be able to use the current_user to change price accordingly
    # Example: user.premium? ? ticket_price/2 : ticket_price
    ticket_price
  end
end
class Checkout < ActiveRecord::Base
  attr_accessible :event
  belongs_to :event
  def total
    event.checkout_price
  end
  def free?
    total == 0
  end
end
明らかに定義できますcheckout_price(user)が、すべての場所 (例: event.checkout_price(current_user)、checkout.total(current_user)、checkout.free?(current_user)) に渡す必要があります。
モデルからアクセスするのは悪い習慣であることは知っていますcurrent_userが(絶対にそうしたくありません)、current_user常にパラメーターとして渡す以外に別の解決策がありますか?