Skip to content

Instantly share code, notes, and snippets.

@bschaeffer
Last active August 29, 2015 13:57
Show Gist options
  • Save bschaeffer/9674844 to your computer and use it in GitHub Desktop.
Save bschaeffer/9674844 to your computer and use it in GitHub Desktop.
dates as string
var dateComputed = function(prop) {
var mProp = prop + 'Month',
yProp = prop + 'Year';
return Ember.computed(mProp, yProp, function(key, value) {
if (arguments.length == 2) {
// setter... maybe moment.js
} else {
// getter... maybe moment.js
}
});
}
App.ThingWithDate = DS.Model.extend({
startedAtMonth: DS.attr('number'),
startedAtYear: DS.attr('number'),
startedAt: dateComputed('startedAt'),
endedAtMonth: DS.attr('number'),
endedAtYear: DS.attr('number'),
endedAt: dateComputed('endedAt')
});
class ThingWithDate
validates_numericality_of :started_at_month, :started_at_year, :ended_at_month, :ended_at_year,
only_integer: true
end
class ThingWithDateSerializer
attribute :started_at_month, :started_at_year, :ended_at_month, :ended_at_year
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment