Skip to content

Commit

Permalink
use rails helper for inclusion validation
Browse files Browse the repository at this point in the history
  • Loading branch information
justinbburris committed Apr 21, 2013
1 parent 7965a87 commit 6575d93
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions app/models/temperature_sensor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,7 @@ class TemperatureSensor < ActiveRecord::Base

validates_presence_of :arduino_id, :data, :unit

validate :valid_temperature_type

def valid_temperature_type
unless TEMPERATURE_TYPES.include?(self.unit)
errors.add(:unit, "Unit must be of type : #{TEMPERATURE_TYPES.join(', ')}" )
end
end
validates :unit, inclusion: { in: TEMPERATURE_TYPES }

def as_json(options = {})
super(only: [:capture_time, :data, :unit, :created_at])
Expand Down

0 comments on commit 6575d93

Please sign in to comment.