I am confused at how EmberJS uses inflection to fetch data from local database.
Given that I have a model called Post, I have seen instances of:
this.store.find('post', 1); //This one makese sense to me. Find a record of post with ID 1
I am more confused at when the tutorial starts adding/omitting 's'.
What are the differences between:
this.store.find('post');
this.store.find('posts');
this.store.all('post'); //This one also makes sense. Find all records of post.
The one that specifically confuses me is this.store.find('posts'); when I only have Post model, because it will actually throw an error telling me that No model was found: posts. Nonetheless, I still see it in the tutorial and getting started. Is this just a typo in the tutorial? This is the toturial that I am referring to:
http://emberjs.com/guides/routing/defining-your-routes/
and go to Dynamic Routes section.
Turning my previous comments into an answer in case someone else stumbles upon this before a fix is live.
I feel this has been wrongly downvoted. It is actually a mistake with the guides, as the singular form should be used throughout. The OP's confusion was entirely warranted.
The PR submitted to correct this issue has already been merged.
Related
I have a problem using ember-bootstrap to render a form. When the route is visited nothing is rendered and in the console the message
appears.
The project is a Bootstrap 3 project and I have just installed ember-boostrap. To do that I did the following :
ember install ember-bootstrap
ember generate ember-bootstrap --preprocessor=sass
ember generate ember-bootstrap --bootstrap-version=3
From reading the doco I believe that was the correct sequence of commands ?
I then created a new route and in the template I put the following :
{{#bs-form formLayout=formLayout model=this onSubmit=(action "submit") as |form|}}
{{form.element controlType="email" label="Email" placeholder="Email" property="email" required=true}}
{{form.element controlType="password" label="Password" placeholder="Password" property="password" required=true helpText="Minimum 6 characters"}}
{{form.element controlType="radio" label="Radio" property="radio" options=radioOptions optionLabelPath="label"}}
{{form.element controlType="checkbox" label="Checkbox" property="checkbox"}}
{{form.element controlType="textarea" label="Textarea" property="textarea"}}
{{bs-button defaultText="Submit" type="primary" buttonType="submit"}}
{{/bs-form}}
{{outlet}}
Which is the sample template from the form component in the ember-bootstrap doco .
As I said when I go to visit the the new route I get nothing rendered and the error message shown above.
I feel like I must have overlooked some part of the directions ... is there something obviously missing ?
EDIT IN RESPONSE TO ANSWER FROM REAL_ATE
So to respond to the points raised by by Chris (real_ate) below. I'm using Ember 3.8 .
Now I was really pleased to feature on the excellent "May I Ask A Question" and I hadn't yet watched this weeks so I went off to watch. It seemed really odd that you were getting a different error than I was so I decided to start a new project and attempt my own reconstruction.
What I found was that I got exactly the error you saw (others can view that segment of the vid here) and not the one I had shown the screen shot of.
So I'm pretty puzzled about this but it does confirm your finding.
My best guess is this ... at about the same time I had been working through some issues with another addon and to document the process I had taken some screen dumps of those errors. I believe I may have picked the wrong screen dump and pasted it into the question. Oddly enough Chris mentioned something at the start of the segment about me not having actually copied the stacktrace but instead having used a screen shot of the stacktrace - perhaps if I'd actually copied the stacktrace I would have been less likely to do what, it seems likely, I did.
So ... for the sake of posterity the initial error was ...
Uncaught Error: Assertion Failed: An action named 'submit' was not found in <est#controller:login::ember231>
at assert (index.js:163)
at makeClosureAction (glimmer.js:6069)
at action (glimmer.js:5995)
at Object.evaluate (runtime.js:266)
at AppendOpcodes.evaluate (runtime.js:72)
at LowLevelVM.evaluateSyscall (runtime.js:3471)
at LowLevelVM.evaluateInner (runtime.js:3417)
at LowLevelVM.evaluateOuter (runtime.js:3409)
at VM.next (runtime.js:5530)
at TemplateIteratorImpl.next (runtime.js:5632)
Which was resolved by providing a 'submit' action on a controller created for the purpose and that then revealed a different issue with the example .hbs from ember-bootstrap including formLayout=formLayout which doesn't exist unless you've defined it and the error for that looks like this ...
Uncaught Error: Assertion Failed: must provide a valid `formLayout` attribute.
at Object.assert (index.js:163)
at Class.<anonymous> (bs-form.js:11)
at ComputedProperty.get (metal.js:2966)
at _get (metal.js:1591)
at RootPropertyReference.compute (glimmer.js:535)
at RootPropertyReference.value (glimmer.js:384)
at SimpleClassNameBindingReference.compute (glimmer.js:4002)
at SimpleClassNameBindingReference.value (reference.js:367)
at ClassListReference.value (runtime.js:1283)
at ComponentElementOperations.flush (runtime.js:1645)
... that was resolved as I described in my answer below .
So thanks to Chris and Jen and sorry for the misleading question .
Well I'm going to answer this myself for the sake of others who might have the same issue. I got some help from the add-on maintainer via the Emberjs discord and to quote him ...
The examples on ember-bootstrap.com are unfortunately not very smart,
in that they show bounded properties as such and not with the actual
value. For example that formLayout=formLayout only makes sense if
you also have a formLayout property on your controller. If that's
not the case (which I assume), formLayout will be undefined. Can you
try removing that and see if it helps? (or replace with a constant
value like formLayout="horizontal")
I did what he suggested and it resolved the problem.
thanks for the question and for giving such a complete example of how to recreate the problem.
I spent some time trying to recreate the problem that you have but I couldn't find the same issue and I wasn't able to get it to error in the same way as you described. I even tried this in an older version of Ember to see if it was something to do with that and it didn't help.
One thing that I did learn when I was trying this out was that the initialisation that you're doing as 3 different steps can actually be done on all one line:
ember install ember-bootstrap --preprocessor=sass --bootstrap-version=3
It shows an error that --preprocessor is not a known parameter for ember-cli but it still works as expected 😂
We also hit into the same issue where we needed to define formLayout for the form to get it to work, but the error we saw wasn't the same as the one you had 🤔 Could you tell us what version of Ember you're working on?
I can see that you have answered your own question already but I would still be interested in getting to the bottom of the error that you saw (if you're interested)
This question was answered as part of "May I Ask a Question" Season 2 Episode 3. If you would like to see us discuss this answer in full you can check out the video here: https://youtu.be/nQsG1zjl8H4
If an user modifies the dynamic segment (object ID) in the URL of an Ember App with Ember Data, what's the best practice to handle these URLs as these might refer to non existing Model entries?
In a minimal example one can observe, that for each call with a non-existent ID (for example http://emberjs.jsbin.com/hurozaju/9#/color/30) there is an empty object added to the local ember data store. This is easily observable by the increasing number of "dots" in the output.
The error-action of App.ColorRoute redirects (as intended) to "colors" in case there is a 404 occurring while fetching the model by ID.
Why is there a "new" Object in the store?
Shouldn't the data be left unmodified?
Is there a chance to prevent the creation of new objects in this case?
I spend some time with this problem and i think this is ember-data beta-7 bug. Please report this issue in github.
here is example code how to work around this issue jsbin. This is tested with data-beta.7 and work and with data-beta.4 not working.
Sorry for not waiting as anounced...
This issue is now reported to ember-data on github.
given this fiddle ( I couldn't make it work, i'm sorry and very frustrated): i don't understand why, when i ask for a book detail, ember is asking not asking my books/book, but my book template. Is that a feature or i'm doing anything wrong?
And, in addition, when i structure my files tree correctly, asking for book detail gives:
-at 1st try: OUTPU: OUTER
-at 2nd try: OUTPUT: Uncaught You can't call renderToBufferIfNeeded on a destroyed view
and i really can't understand why
thank you
First, of all, here is a working version of your fiddle with latest ember.js and ember-data: http://jsfiddle.net/va9gc/
The reason why ember is looking for book template instead of books/book is because you define book as a resource, not as a route. This is explained here: http://emberjs.com/guides/routing/defining-your-routes/#toc_nested-resources
Hello Graph API experts,
When you call /[post_id , the result contains "comments" field which has "count" field that is supposed to have the total number of comments for this particular post.
Now, if you call /[post_id]/comments , you get the actual comment data, one by one.
The problem I am facing is that, when I compare the "comments.count" field's value and the number of all of the actual comment data returned, they are different.
What's even worse, if you then look at the same post on Facebook.com's Timeline where you can see the number of comments for that post (i.e. "view all * comments" link), this number is also different from the "comments.count" field value.
And this is not only happening to one post, but to many of them - I observe this tend to happen more to posts with more than 100 comments (I actually counted all the comments on Timeline, and it matched the number of the actual comment data returned from /[post_id]/comments API call).
Is this a normal API behaviour? Which number should I or would you trust if this is the way it is?
ok, when you looking some facebook comment counts on some timeline posts, you woulld see that count for ex. 16 comments, and when you try to count comments manually on the post you may see it's looking 15 comments, so where is it that missing comments ? is that a wrong count by facebook ? no not actually, it's because, some people changing profile privacies as like don't show my comments people who aren't my friends, or we haven't any mutual friends, etc. it's because you cannot get these privatized comments from graph api, but these comments aren't excluding in total count. So what's the solution, just be sure get all the data correctly what facebook provide you. And compare it, how many comments looking like missing, and show missing counts as private comments count in your application. I think is much better.
Welcome to the world of Facebook API programming. Yes, this is normal (but apparently not desired) API behavior. This is one of the inconsistencies we're faced with when programming around their API. CBroe is probably correct in his comment above, it is data inconsistencies between servers in their API cluster.
in addition to this there are problems with pagination, you can use the offset + limit parameters to say how much data you want and from where to take it, if you deal with number of posts, you can say offset=0 and limit=50 and it'll work, but then if you try offset=100 and limit=50 it might return empty data, but then try offset=100 and limit=100 and it'll return 100 posts.
the api is just buggy and full of inconsistencies which don't seem to have any way to solve them.
I think we got oversold on the opengraph, I don't think it's what facebook told us it would be and I'm starting to feel the burn from selling that to my boss and finding out that I perhaps can't deliver :(
I did implement some code with ember-data talking to a sinatra json-app. Method findAll works as expected and load of records.
Also I did implement the updateRecord-method in the DS.Store.create, but don't really know how to update and commit. Please, see the code here (for sake of brevity, I didn't include the jquery functions): http://pastie.org/3197008
I tried the following:
a = Todos.records.objectAt(0).set("text", "should be so")
a.store.commit()
But I get the following error: TypeError: Object (subclass of DS.State) has no method 'enter'
How should I update records? Or did I forget to implement something for the update?
Thanks in advance!
I had the same problem. I think this is a bug in ember-data. The problem is that the code was not properly initializing certain substates, and those substates were not state instances but rather state classes.
I fixed the problem by defining a function that generates a new state instance (with properly created substates) each time it is called. You can find my changes here.
I also requested that the ember-data folks pull my fix, so hopefully this issue will disappear soon. You can view the pull request for discussion.
i had the same problem this morning. Use the emberjs git version