0

I've been trying to render data in the same view and cant seem to get something right. I want to be able to render the rating for each location on the locations show outlet.

Here's what I have got.

I've tried different routes and different nesting for resources as well as rendering different things in the rails controllers. I can get back a hash of the correct ratings but dont know how to display it.

I'm assuming that something is wrong in my rails controllers or something I need to do in the Handlebars views. I've tried so many things so I didnt even post my rails stuff. If this Ember stuff is correct what is the correct way to render this with handlebars and the rails controller.

App.Router.reopen
  location: 'history'
  rootURL: '/'

App.Router.map ->
  @resource 'users', ->
    @route 'new',
@route 'edit',
      path: '/:user_id/edit'
    @route 'show',
      path: '/:user_id'
  @resource 'locations', ->
    @route 'new',
    @route 'show',
      path: '/:location_id'
  @resource 'ratings', ->
    @route 'new',
    @route 'show',
      path: '/:ratings_id'

App.Rating = DS.Model.extend(
  rating: DS.attr('string', defaultValue: "-0")
  description: DS.attr('string', defaultValue: "No Description Provided")
  location: DS.belongsTo("App.Location")
  )

App.Location = DS.Model.extend(
  name: DS.attr('string', defaultValue: "")
  address:  DS.attr('string', defaultValue: "")
  city: DS.attr('string', defaultValue: "")
  state:DS.attr('string', defaultValue: "")
  ratings: DS.hasMany('App.Rating')
  fullAddress: (->
    "http://maps.google.com/?q=#{@get('address')},#{@get('city')},#{@get('state')}}"
  ).property('address')
)


App.Store = DS.Store.extend(
  revision: 11
  adapter: DS.RESTAdapter.create(mappings:
    ratings: App.Rating
  )
)
Garrett Boone
  • 234
  • 3
  • 12

1 Answers1

0

Little hard to tell without the template, routes or controllers.

Since you have a relation between the models, the way to reference it in your template would be location.ratings where location would be the variable in your #each. This works quite well. If you have sideloaded the ratings, you will have access to them immediately. Or it will make a request to get these ratings from the server.

The other main idea to reference data from different controllers is to use the needs API.

needs: 'foo',
ratingsBinding: 'controllers.foo'
Darshan Sawardekar
  • 5,065
  • 2
  • 21
  • 31