Skip to content

Instantly share code, notes, and snippets.

@tammersaleh
Created September 15, 2009 20:55
Show Gist options
  • Save tammersaleh/187639 to your computer and use it in GitHub Desktop.
Save tammersaleh/187639 to your computer and use it in GitHub Desktop.
class Counterpoint < ActiveRecord::Base
belongs_to :owner, :class_name => "User"
validate :ensure_owned_by_journalist
def self.creatable?
return false unless user_from_session
return false if user_from_session.company_representative?
return true
end
private
def self.user_from_session
UserSession.find && UserSession.find.user
rescue Authlogic::Session::Activation::NotActivatedError
nil
end
def ensure_owned_by_journalist
errors.add_to_base("You must be a journalist to create a counterpoint.") unless Counterpoint.creatable?
end
end
- if Counterpoint.creatable?
= link_to "Add counterpoint", new_note_counterpoint_path(note), :class => "new_note_counterpoint_link"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment