Pergunta

So I'm making a little toy ember app that will present a user with some improv prompts to create a comic strip out of. After a certain amount of time, the user will be able to upload their completed comic.

I've got the whole thing working up to the point of preseting the form to the user to upload their completed comic.

So far, everything is one route, controller and model (prompts). At the end though, they really should be working with a comic record. At the present, everything is in the same template, and I put the upload form into a view:

App.UploadComicView = Ember.View.extend
  templateName: "upload_comic"
  tagName: "form"
  classes: ['form-horizontal']

  submit: ->
    @get('controller').uploadComic(@get('comicTitle'))
    false

For the following model:

App.Comic = DS.Model.extend
  title: DS.attr('string')

And I attempted to do the following in the prompts_controller:

uploadComic: (title) ->
  App.Comic.createRecord(title: title)
  @get('store').commit()

However, that attempts to sent a update action to the prompts controller on the backend, not a create request to the comics controller.

So it seems like I really should have a separate ember controller/template/model/route for comics, but I'm not sure how to get from the prompts controller at the end of the challenge to the comics controller in order to create a new comic object in the database. To make matters worse, I also really need to send the selected prompts from the current prompts controller to the new context.

What would be the best way to proceed?

Foi útil?

Solução

When you do a App.Comic.createRecord it will do a POST to /comics with the request body {title: 'your title'}. This is regardless of which controller/location you do it from. Are you saying that it goes elsewhere? Please post a jsbin if this is the case.

Regarding the need to communicate with/access other controllers, you can use the needs declaration inside the other controller.

needs: 'comics'
comicsBinding: 'controllers.comics'

You can now access the comics controller via this.get('comics') inside it.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top