Note that there are some explanatory texts on larger screens.

plurals
  1. POEmber Edit Template
    primarykey
    data
    text
    <p>I have an ember app which has a <code>profiles</code> route to display a title and a description of a particular item from the database. I want to create an <code>edit</code> page for that data, as in CRUD in ember. I implemented an <code>edit</code> route under the <code>profiles</code> resource route. </p> <p>The <code>index</code> template works fine, it successfully populates the data from the database and the results show in the template. However, as soon as I declare a controller for that route and add an action to that controller the template breaks.</p> <p>Here is the app.js code for the app.</p> <pre><code>App.Profile = DS.Model.extend({ title: DS.attr('string'), description: DS.attr('string') }); App.Router.map(function(){ this.resource("about", function(){ this.route("create", {path: '/create'}); }); this.resource('profiles', {path: '/profiles/:profiles_id'}, function(){ this.route('edit'); }); this.resource('login'); this.resource("logout"); }); App.ProfilesController = Ember.Controller.extend(); App.ProfilesRoute = Ember.Route.extend({ model: function(params) { NProgress.start(); var data = App.Profile.find(params.profiles_id); data.then(function(){ NProgress.done(); }); return data; } }); </code></pre> <p>The Html Code for profiles:</p> <pre><code>&lt;script type="text/x-handlebars" data-template-name="profiles"&gt; &lt;div class="container"&gt; &lt;div class="row"&gt; &lt;h1&gt;{{title}}&lt;/h1&gt; &lt;p&gt; {{description}} &lt;/p&gt; &lt;form {{action edit on="submit"}}&gt; {{input value=title type="text" placeholder="Title"}} {{textarea value=description}} {{input class="button" type="submit" value="Edit"}} &lt;/form&gt; &lt;/div&gt; &lt;/div&gt; &lt;/script&gt; </code></pre> <p>At this point everything works fine. but as soon as i add edit action to ProfileController, when i load the page in the browser only the form with no data is shown. what went wrong?</p> <p>when i add this code to the ProfilesController onyl the form with no data is shown:</p> <pre><code>App.ProfilesController = Ember.Controller.extend({ edit: function(){ var self =this, data = this.getProperties('title', 'description'); self.set('errorMessage', null); self.set('successMsg', null); Ember.$.put('profiles', data, function(){ NProgress.start(); }).then(function(response){ NProgress.done(); if(response.success){ }else { self.set('errorMessage', response.message); console.log(response.message); } }); } }); </code></pre> <p>I want to create an action when the form is submitted, the edit action get triggered and do the put on the server, i have php laravel 4 backend at the server to handle the request RESTfully.</p> <p>I tried to implement the above code under edit template as in profiles/edit template but i couldn't make it work, so i pasted the code in index template of profiles.</p> <p>Ember displays this log on console</p> <blockquote> <p>generated -> route:profiles.index Object {fullName: "route:profiles.index"} ember-1.0.0.js:356</p> <p>Rendering application with default view &lt;(subclass of Ember.View):ember330> Object {fullName: "view:application"} ember-1.0.0.js:356</p> <p>Rendering profiles with default view Object {fullName: "view:profiles"} ember-1.0.0.js:356</p> <p>generated -> controller:profiles.index Object {fullName: "controller:profiles.index"} ember-1.0.0.js:356</p> <p>Could not find "profiles.index" template or view. Nothing will be rendered Object {fullName: "template:profiles.index"} ember-1.0.0.js:356</p> <p>generated -> route:index Object {fullName: "route:index"} ember-1.0.0.js:356</p> <p>generated -> route:about.index Object {fullName: "route:about.index"} ember-1.0.0.js:356</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload