Skip to content

Commit

Permalink
Merge pull request #999 from transitland/entity-attribute-validate
Browse files Browse the repository at this point in the history
Entity attribute validate
  • Loading branch information
doublestranded authored Mar 1, 2017
2 parents 79b32f7 + b70aa41 commit aa96a95
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/models/entity_with_issues.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,12 @@
class EntityWithIssues < ActiveRecord::Base
belongs_to :issue, dependent: :destroy
belongs_to :entity, polymorphic: true

validate :entity_attribute_exists?

def entity_attribute_exists?
unless entity.attributes.include?(entity_attribute) || entity_attribute.nil?
errors.add(:entity_attribute, "#{entity_attribute} does not exist")
end
end
end

0 comments on commit aa96a95

Please sign in to comment.