Computed properties with ember-model? - ember.js

I have a simple model that worked with ember-data but not sure how to get this to work with ember-model?
Acme.App = Ember.Model.extend(
post_screenshot_url: Ember.attr()
post_screenshot_url_thumb: (->
#get('post_screenshot_url') + '/?thumb=true'
).property('')
)
This used to work with ember-data but now this doesn't work with ember-model. Thoughts?

It's working for me with latest Ember and Ember Model, check this JSBin:
http://emberjs.jsbin.com/obeHimU/3/edit?html,js,output
PS: You probably should add "post_screenshot_url" to the properties call on "post_screenshot_url_thumb" so it gets correctly updated.

Related

Ember Serialize in link-to doesn't work since 1.4.0?

Since I've upgraded from 1.3.2 to 1.4.0 I've got many problems about the serialization of the link-to url.
In the previous version, for each link-to we pass in the serialize method but it's not the case anymore, Can someone tell me why and if there is another alternative?
Thank u
I've found the solution !
Actually my route looks like this :
this.route('projects', {
path: '/projects/:pageProjects/:colProjects/:ascProjects'
});
And my handlebar looks like this :
{{#link-to "projects"}}
{{trc "plural" "Signed"}} <span class="pull-right">{{count.approuvedCount}}</span>
{{/link-to}}
The fact is that sometime I needed to set a default model directly in the serialize method which is not a great solution and I know it.
Since the ember ugrade to 1.4.0, if we don't pass any model parameter into the link-to, it doesn't call the serialize method anymore :).

Ember Data override find method

I need to override the find() method in ember-data to make it compatible with my app. Its not a huge modification that I have to do, but I don't know where to start.
So far when I try to do this : this.store.find('enquiry'); Ember-Data is trying to fetch information from http://localhost/enquiries instead of http://localhost/enquiry. My problem is that I don't need to get the plural of my url..
I thought also using the jquery method but, I would rather using Ember-Data for this. How can I do that ?
Another question : After this is working, is Ember-Data generate dynamically the model in the app ? Because I have a lot field in my JSON and I can't write them down manually...
Can I do something like this :
App.Store = DS.Store.extend({
adapter: '-active-model'
});
App.Enquiry = DS.Model.extend();
Thanks for your help !
This page will show you exactly how to use a custom adapter in your application. And this page will show you how to override a method in your subclass.
I didn't see your response on the Ember forum yesterday, but in my opinion, you'd still be better off writing your own adapter. It seems like you're going to do more work trying to modify the REST adapter than if you just created your own.
But if you still want to extend the rest adapter, here is how:
App.ApplicationAdapter = DS.RESTAdapter.extend({
find: () {
//...
}
}):
As for your second question, no, Ember-Data will not pick up the fields automatically. I'm pretty sure it'll throw an error if you include fields in your JSON that are not declared in the corresponding model. This is by design. If you don't know your fields at development-time, how can you use them in templates or controllers?

How to enable query-params-new feature using ember-rails

I am having trouble using the query-params-new feature.
My version of ember is 1.4.0-beta.2.
Ember.js is loaded into my rails app through the ember-rails and ember-source gems.
Before initializing the Ember App I turn on the feature like so.
Ember.FEATURES["query-params-new"] = true
After doing so I get the following error when navigating to any route.
Error while loading route: TypeError: Object [object Object] has no method 'paramsFor' at Ember.Route.Ember.Object.extend.deserialize
Am I missing something? Do I need to define a paramsFor method at each route?
I'm having the same problem, I noticed this issue mentioning the problem, and attributes it to misusing the new query params API. Where you using the prior implementation?
Edit:
My problem was how I was enabling it.
I was following the prior method of simply passing a value to Ember.FEATURES:
Ember.FEATURES['query-params-new'] = true;
However, the docs now specify the correct method (which also needs to happen before the Ember js file is loaded by the browser):
ENV = {FEATURES: {'query-params-new': true}};
I forgot coffee-script wraps everything in a top-level function.
Here is the way I do it in coffee-script.
#= require_self
#= require handlebars
#= require ember
#ENV = {FEATURES: {'query-params-new': true}}

Ember.js "isDirty" not being cleared on save with both Epf and Ember-Data (1.0.0.beta.2)

I'm having a problem using Ember. When I change a model, its "isDirty" flag becomes true, which is what I expect.
However, after that its "isDirty" flag is true, even after I save that model.
Here's a minimal Rails + Ember project (so I can actually save the model) that shows the situation:
https://github.com/csterritt/etst
Am I doing something wrong? Is this expected behavior?
Thanks!
Edit: Turns out that, as Jeremy Green pointed out below, the "isDirty" flag works for Ember Data.
And, it works with the current Ember 1.0.0 (standard, not -latest) and Ember Data beta.
I was doing:
isClean: ( ->
! #get("isDirty")
).property("name", "age", "favorite_food")
Which was due to a misunderstanding on my part. Changing this to:
isClean: ( ->
! #get("isDirty")
).property("isDirty")
Works properly.
Unfortunately, this doesn't solve the Epf version's problem. Epf-ites?
Can you post a JSBin demonstrating the issue? Here's a simple JSBin with the FixtureAdapter that shows the isDirty flag being cleared correctly.
http://jsbin.com/ucanam/1058/edit
I also just double checked in one of my apps that's using the RESTAdapter against a real API, and it is also clearing the flag.
[EDIT] : The JSBin that I posted is running ember-data-latest, and my real app is using beta 2.
With regards to EPF, isDirty is currently a volatile computed property. I will change this soon.

ember data isLoad on collections

I use emberjs-data
allProcessPointsAreLoaded:(->
#get("reportDefinition.virtualColumns").everyProperty("processPoint.isLoaded", true)
).property("reportDefinition.virtualColumns.#each.processPoint.isLoaded")
my property is not updated when processPoint.isLoaded changed to true. Any thoughts?
The latest ember-data has an isLoaded property on the whole content collection, instead of just each field. In my view I monitor the path 'controller.content.isLoaded' to determine when all the content is there.
I believe that #each can only currently support one nested property "reportDefinition.virtualColumns.#each.processPoint" but not "reportDefinition.virtualColumns.#each.processPoint.isLoaded". Here's the github issue that I found.
I've worked around it by adding a property to proxy to isLoaded. So you would have something like:
processPointLoaded: function() {return this.get('processPoint.isLoaded')}.property('processPoint.isLoaded')
I hope that helps!