Skip to content

Instantly share code, notes, and snippets.

@rlivsey
Created May 22, 2014 16:12
Show Gist options
  • Save rlivsey/b6c15ff3acf361cf344c to your computer and use it in GitHub Desktop.
Save rlivsey/b6c15ff3acf361cf344c to your computer and use it in GitHub Desktop.
date query params
IndexController = Ember.Controller.extend
queryParams: ["date"]
date: ((k,v) -> v || moment()).property()
`export default IndexController`
IndexRoute = Ember.Route.extend
queryParams:
date:
replace: true
serializeQueryParam: (value, urlKey, defaultValueType) ->
return @_super(value, urlKey, defaultValueType) unless value && urlKey == "date"
# value is not a moment at this point for some reason, but coerces fine
moment(value).format("YYYY-MM")
deserializeQueryParam: (value, urlKey, defaultValueType) ->
return @_super(value, urlKey, defaultValueType) unless urlKey == "date"
date = moment(value, "YYYY-MM")
date = moment() unless date.isValid()
date
`export default IndexRoute`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment