Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Paper < ActiveRecord::Base
- # Validation
- validates_presence_of :title, :contact_email, :abstract
- # We don't want two papers with the same title now, do we?
- validates_uniqueness_of :title
- # Checking if the email address is valid one
- validates_format_of :contact_email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
- validate :abstract_cannot_contain_latex
- # TODO: We need to add another field for password confirmation
- # and use validates_confirmation_of
- # We indicate that topics associated to the paper can be fetched
- # through the paper_topics join table
- #has_many :paper_topics
- #has_many :topics, :through => :paper_topics
- has_many_and_belongs_to_many :topics
- protected
- def abstract_cannot_contain_latex
- # TODO: Make the validation non-naive and use i18n on the error message
- errors.add(:abstract, "The abstract cannot contain LaTeX expressions, please escape them appropriately") if %w{\\ ~ $ _}.any? {|w| abstract.include? w}
- end
- end
Add Comment
Please, Sign In to add comment