1

I am trying to add an ember app to an existing (large) rails app. If it works out, I would like to use ember for many new areas of the app, but I'm starting small.

Essentially, the user is on a rails Students index page, clicks on one of many links to manage a student's IEPs, and then the modal box containing the ember app is shown. When we first spiked this back in May, we did this as follows:

showDialog: (url) ->
  studentId = ...
  $('#emberDialog').dialog
    open: ->
      student = App.Student.find(studentId)
      App.Router.router.transitionTo('studentIeps.index', student)

Now that we are picking this up again, I'm finding that in the bump from Ember V1.0.0-rc.5-80-gf54e8ef to V 1.1.3+pre.e0ffbf84 and Ember-data from V0.13-30 to V1.1.0-beta.3-4 the Model.find methods have been removed.

Is there a supported way to do this any longer? I'm trying to build an instance of a model external to the ember app, and then use that to set the ember app's current route. Halp?

1 Answer 1

1

You can fetch an instance of the application controller from the container, from there you can do everything you were doing before. The controllers have an instance of the store on them, which is how you get models now. You'll probably have some other issues with your data/adapters, see the transition document: https://github.com/emberjs/data/blob/master/TRANSITION.md

showDialog: (url) ->
  studentId = ...
  $('#emberDialog').dialog
    open: ->
      appController = App.__container__.lookup('controller:application')
      store = appController.get('store')
      student = store.find('student', studentId)
      appController.transitionToRoute('studentIeps.index', student)
Sign up to request clarification or add additional context in comments.

4 Comments

While this would work right now, I'm not sure I'm comfortable deploying this to production. App.__container__.lookup() is a major hack into the internals. Has Ember data completely removed a public api to access store externally? Or maybe there is a better way to get an instance of a model outside the ember app?
I can understand your concern. The double __ looks hacky, and rightfully so. Yehuda didn't want people touching internals from the external world ;) Using the router in the current fashion you are doing is playing with ember's internals. That isn't a public hook that's discussed or documented on their site. Additionally they intentionally only made the store available to the controllers/routes to avoid people using the store inappropriately (aka at the view layer, inside components, etc).
So, the true answer to this question is "Ember doesn't support that anymore." Thanks, that's actually exactly what I need to know :)
Yeah, sorry I didn't make that clear. They discourage it, but you can still get to it using the internals.

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.