Created
September 15, 2009 20:55
-
-
Save tammersaleh/187639 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- 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