Skip to content

Instantly share code, notes, and snippets.

@tpendragon
Last active December 17, 2015 15:29
Show Gist options
  • Save tpendragon/5631691 to your computer and use it in GitHub Desktop.
Save tpendragon/5631691 to your computer and use it in GitHub Desktop.
class BooleanSurvey < Survey
def self.translate_answer(answer)
ActiveRecord::ConnectionAdapters::Column.value_to_boolean(answer)
end
end
class Survey < ActiveRecord::Base
attr_accessible :end_date, :start_date, :title, :question
validates :title, :presence => true
# Returns a string interpretation of the answer given.
# @note This should be overriden by specific survey types.
def self.translate_answer(answer)
answer.to_s
end
end
subject.class
=> Survey::BooleanSurvey(id: integer, title: string, start_date: date, end_date: date, created_at: datetime, updated_at: datetime, question: string, type: string)
subject.class.translate_answer('test')
=> "test"
Survey::BooleanSurvey.translate_answer('test')
=> false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment