Guest User

Untitled

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