All pastes #427192 Raw Edit

Untitled

public ruby v1 · immutable
·published 2007-04-06 17:34 UTC
rendered paste body
class Contribution < ActiveRecord::Base  belongs_to :contributor, :class_name => 'User', :foreign_key => 'user_id'  belongs_to :post  # TODO move this to a configuration value  CONTRIBUTION_ROLES = {    'Photographer' => 'Photos by %s',    'Writer' => 'Words by %s',    'Research' => 'Research by %s'  }  class << self    def contribution_roles; CONTRIBUTION_ROLES; end    def contribution_role_names; CONTRIBUTION_ROLES.keys; end    def contribution_role_display_name(role_name); contribution_roles[role_name]; end  end  def contribution_name    self.class.contribution_roles[contribution_role] % (contributor.first_name + ' ' + contributor.last_name)  end  validates_presence_of :post_id, :contribution_role  def validate    unless self.class.contribution_role_names.include? self.contribution_role      errors.add(contribution_role, 'should be:' + self.class.contribution_role_names.join(', '))    end  endend##########class ArticlePost < Post  has_many :contributors, :through => :contributions  has_many :contributions, :foreign_key => 'post_id'end