Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. class Source < ActiveRecord::Base
  2. belongs_to :source_type
  3. def url=(value)
  4. SourceType.each do |type|
  5. # here i match type's regexp to input value and if match,
  6. # assign it to the new source object
  7. end
  8. end
  9. end
  10.  
  11. class Person
  12. include ActiveModel::Validations
  13. attr_accessor :title
  14.  
  15. validates :title, presence: true
  16. end
  17.  
  18. class Source < ActiveRecord::Base
  19. belongs_to :source_type, inverse_of: :sources
  20. attr_accessor :url
  21. end
  22.  
  23. class SourceType < ActiveRecord::Base
  24. has_many :sources, inverse_of: :source_type
  25. validates :source_type_attr, presence: { if: :url_match? }
  26.  
  27. def url_match?
  28. self.sources.url == [your_regex]
  29. end
  30. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement