Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Source < ActiveRecord::Base
- belongs_to :source_type
- def url=(value)
- SourceType.each do |type|
- # here i match type's regexp to input value and if match,
- # assign it to the new source object
- end
- end
- end
- class Person
- include ActiveModel::Validations
- attr_accessor :title
- validates :title, presence: true
- end
- class Source < ActiveRecord::Base
- belongs_to :source_type, inverse_of: :sources
- attr_accessor :url
- end
- class SourceType < ActiveRecord::Base
- has_many :sources, inverse_of: :source_type
- validates :source_type_attr, presence: { if: :url_match? }
- def url_match?
- self.sources.url == [your_regex]
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement