dgeb / ember_data_example Goto Github PK
View Code? Open in Web Editor NEWA simple Rails app for testing CRUD with ember.js and ember-data.js
License: MIT License
A simple Rails app for testing CRUD with ember.js and ember-data.js
License: MIT License
Two possible approaches:
Rather than doing something custom, I'd like to figure out if ember-data will provide a model state concept for handling this.
Many thx for the example, that really got me going -
Alas, I tried it with the current version of ember-data(emberjs/data@bd9998f) and ran into some issues: It looks like the properties
collectionUrl: '/contacts',
resourceUrl: '/contacts/%@',
resourceName: 'contact'
on the Contact-Model are not supported by the curent rest-adapter. As far as I have seen, they are ignored completely - however the RestAdapter has gotten a builUrl-function that supports namespaces and suffixes. So, in order to get models running with a different resourceUrl, I had to set up the RestAdapter like this:
store = DS.Store.create
revision: 3,
adapter: DS.RESTAdapter.create({ bulkCommit: false, namespace: "admin" })
which now mounts the contacts into "/admin/contacts". As far as I could see, the RestAdapter does currently not support a configuration per model(correct me, If I'm wrong...). So, if somebody needs models from another namespace, this is the place to look into...
Cheers
Stefan
is there a tutorial that walks through how this app was created?
in ember_data_example github source code. It use this approach
transitionAfterSave: function() {
// when creating new records, it's necessary to wait for the record to be assigned
// an id before we can transition to its route (which depends on its id)
if (this.get('content.id')) {
this.transitionToRoute('contact', this.get('content'));
}
}.observes('content.id'),
It works fine, but maybe, this function will be executed whenever model's ID property is changed. I'm finding some more semantic way.
I want transition to be executed when the model's status is changed to 'isDirty' = false && 'isNew' == true form 'isDirty' = true, 'isNew' = false.
How can I implement this?
First, thanks for this very helpful project.
It seems that in contacts.hbs, explicitly setting the contentBinding is unnecessary:
{{view App.ContactInListView contentBinding="contact"}}
Works just as well using:
{{view App.ContactInListView}}
Can't work out how or why this is so though. Must be magic.
1 click "add new contact" , then edit interface shows
2 then click "all contact" at left side , then a bug shows
This was intentionally left out initially, as it's unclear how errors should flow from the adapter, and back through the store and model in ember-data.js.
Validations have been added to the Contact model in Rails. If either the first or last name is left blank, a record will not be saved properly. This needs to be conveyed to the user.
Updating the example specs to accommodate for both unit and acceptance tests, and having test_helper use App.reset() instead of deferring and advancing app readiness would be awesome. I've got a good weekend to do this if I can help.
I think it would be neat if this wonderful sample repository would illustrate how to test the Ember application. I'm not very experienced with Rails so I don't know exactly where to put JS tests.
I just wanted to open this issue to start a discussion. Any ideas?
Could not find linecache19-0.5.13 in any of the sources
Could not find ruby-debug-base19-0.11.26 in any of the sources
Changing the Gemfile.lock to use linecache19-0.5.12 and ruby-debug-base19-0.11.25 let me bundle correctly.
If you include the root 'contact' in your json, then the initial load goes all 'null null' for me. If you don't however the ember-data bit that does the json[root] lookup is incorrect and didCreateRecord seems to throw an error. Trying to work through this now, but wanted to document in case I'm doing it wrong or it's a known bug.
I removed app/assets/javascripts/vendor and made the following change to app/assets/javascripts/application.js:
-//= require ./vendor/ember -//= require ./vendor/ember-data +//= require handlebars +//= require ember +//= require ember-data
Does the Observer set up here need to be removed at some point?? I'm wondering how to improve the structure so that the Observer is declared in the class definition with .observes() and so Ember will automatically handle that.
When loading data directly with App.store.loadMany()
, subsequent calls to App.store.findAll()
result in the exception Uncaught Error: <DS.StateManager:ember368> could not respond to event setData in state rootState.loaded.
For ember 1.0, ember data revisions, and perhaps rails 4? This would be a fantastic app to learn ember and db persistence with.
hi, I'm getting this error after running the "rails s" and visiting the page at localhost:3000.
But since I'm not a rails expert I'm not sure if this is a bug a rails related problem...
here is my console output:
alex@leda ~/workspace/ember_data_example » rails s => Booting WEBrick => Rails 3.2.9 application starting in development on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server SECURITY WARNING: No secret option provided to Rack::Session::Cookie. This poses a security threat. It is strongly recommended that you provide a secret to prevent exploits that may be possible from crafted cookies. This will not be supported in future versions of Rack, and future versions will even invalidate your existing user cookies. Called from: /usr/local/Cellar/ruby/1.9.3-p392/lib/ruby/gems/1.9.1/gems/actionpack-3.2.9/lib/action_dispatch/middleware/session/abstract_store.rb:28:in `initialize'. [2013-03-11 20:35:28] INFO WEBrick 1.3.1 [2013-03-11 20:35:28] INFO ruby 1.9.3 (2013-02-22) [x86_64-darwin12.2.1] [2013-03-11 20:35:28] INFO WEBrick::HTTPServer#start: pid=62314 port=3000 Started GET "/" for 127.0.0.1 at 2013-03-11 20:35:45 +0100 Connecting to database specified by database.yml Processing by ApplicationController#index as HTML Rendered application/index.html.erb within layouts/application (3.4ms) Completed 500 Internal Server Error in 143ms ActionView::Template::Error ( (in /Users/alex/workspace/ember_data_example/app/assets/javascripts/templates/_contact_edit_fields.hbs)): 3: 4: <title>EmberDataExample</title> 5: <%= stylesheet_link_tag "application" %> 6: <%= javascript_include_tag "application" %> 7: <%= csrf_meta_tags %> 8: 9: app/views/layouts/application.html.erb:6:in `_app_views_layouts_application_html_erb___1363792714881371063_70207568502280' Rendered /usr/local/Cellar/ruby/1.9.3-p392/lib/ruby/gems/1.9.1/gems/actionpack-3.2.9/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.4ms) Rendered /usr/local/Cellar/ruby/1.9.3-p392/lib/ruby/gems/1.9.1/gems/actionpack-3.2.9/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (0.9ms) Rendered /usr/local/Cellar/ruby/1.9.3-p392/lib/ruby/gems/1.9.1/gems/actionpack-3.2.9/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (8.9ms) [2013-03-11 20:35:46] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
thanks
Currently, validations are handled in forms by bootstrap. This isn't very robust - model-level validations would be better.
this.set('content', App.store.findAll(App.Contact));
does not reload data from the rest adapter
See App.contactsController.loadAll()
After creating a contact, the user is transitioned to the newly created contact's page. Because the contact does not yet have an id, the route is /#/contacts/undefined
. This leads to deserialization problems for the route when using the browser's back button.
First of all it failed because phantomjs wasn't installed on my system, e.g. should be part of the build process as a dependency.
$ npm install phantomjs -g
However, I still get the following error:
$ bundle exec rake test
...
Adding a new contact::with valid data
test_0001_should create the record and then show its details ERROR
Unable to find link or button "Create"
It depends on linecache19-0.5.13, which can't be found.
Because the listing view doesn't get updated fully, new records can't be destroyed without refreshing the listing first.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.