237338834f2f8948e862e91392a8c1b4

How do I turn this into a has_one association? (Possibly has_one + a named scope for size.)

class User < ActiveRecord::Base
  has_many :assets, :foreign_key => 'creator_id'

  def avatar_asset size = :thumb
    self.assets.find :first, :conditions => ["thumbnail = '#{size}' and filename LIKE ?", self.login + "_#{size}.%"]
  end
end

Refactorings

No refactoring yet !

Your refactoring





Format Copy from initial code

or Cancel