1

I'm trying to use a model to create a dynamic route that will show the date in the URL but I'm getting a typedef error and I can't see which get it's talking about and why it's giving me the error. Is it my model or my route that is giving me the error. How do I avoid this from happening when when I try creating dynamic routes? What's a good source or book that can show me the ends and out of Ember?

    var App = Ember.Application.create({
        LOG_TRANSITIONS: true
    });

    App.Router.map(function(year, month, date) {
        this.resource('calendar');
        this.resource('about'); 
        this.resource('utcDate', {path: ':utcDate'});
    });

    App.IndexRoute = Ember.Route.extend({
        redirect: function(){
            this.transitionTo('calendar');
        }
    });

    App.CalendarRoute = Ember.Route.extend({
        model: function(){
            return App.CalendarData.create();
        },
        model: function(params, transition){
            return {utcDate: params.utcDate}
        },
        serializer: function(model){
            return {utcDate: model.get('utcDate')};
        },
        serializer: function(model){
            return {month: model.get('Today')};
        }
    });

    // calendar controller
    App.CalendarController = Ember.Controller.extend({

//something here seems to be throwing an error that I can't troubleshoot       
      utcDate: function() {
        return this.get("model").get("utcDate");
      }.property("model"),

      days: function() {
        return this.get("model").get("days");
      }.property("model"),

      date: function() {
        return this.get("model").get("date");
      }.property("model"),

      month: function(){
        return this.get('model').get('month');
      }.property('model'),

      dow: function(){
        return this.get('model').get('dow');
      }.property('model'),

      year: function(){
        return this.get('model').get('year');
      }.property('model')
    });

    // calendar data
    App.CalendarData = Ember.Object.extend({
        today: new Date(),

        utcDate: function(){
          return this.get('today').getMonth()+1 + '/'+ this.get('today').getDate()+'/'+this.get('today').getFullYear();
        }.property('today'),

        date: function(){
          return this.get("today").getDate();
        }.property('today'),

        days: function(){
          var Mdays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
          var Ndays =  Mdays[this.get('today').getMonth()];
          var days = [];
          var cDays = 0;
          for (var i = 0; i < 5; i++) {
            days[i] = [];
              for (j = 0; j <=6; j++) {
                if (cDays <= Ndays){
                  days[i][j] = cDays++;
                } else{
                  days[i][j] = " "
                }
              }
          }
          return days;
        }.property('today'),

        month: function(){
          var MonthA = ["January", "February", "March", "April", "May", "June", "July",  "August", "September", "October", "November", "December"];
          var month = MonthA [this.get('today').getMonth()];
          return month;
        }.property('today'),

        dow: function(){
          var Weekday = ["Sunday", "Monday", "Tuesday", "Wednesday",  "Thursday", "Friday", "Saturday"];
          var dow= Weekday[this.get('today').getDay()];
          return dow;
        }.property('today'),

        year: function(){
          return this.get('today').getFullYear();
        }.property('today')
    });

http://emberjs.jsbin.com/yicuh/1/

1 Answer 1

1

You've got the model hook and serialize hook defined multiple times.

App.CalendarRoute = Ember.Route.extend({
    model: function(){
        return App.CalendarData.create();
    },
    model: function(params, transition){
        return {utcDate: params.utcDate}
    },
    serializer: function(model){
        return {utcDate: model.get('utcDate')};
    },
    serializer: function(model){
        return {month: model.get('Today')};
    }
});

I guessed I chose one of each, but additionally if an object isn't an ember object you'll need to use Ember.get(object, property) instead of object.get(property).

App.CalendarRoute = Ember.Route.extend({
    model: function(){
        return App.CalendarData.create();
    },
    serializer: function(model){
        return {utcDate: Em.get(model,'utcDate')};
    },
});

http://emberjs.jsbin.com/wemoc/1/edit

Sign up to request clarification or add additional context in comments.

1 Comment

Beautiful! I'm trying to make the utcDate the default route. I seem to have it defined but Ember disagrees with me. Ahh it IS working but as utcDate and not in the format that the utcdate is in. emberjs.jsbin.com/qihuz/1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.