10 ms·
I think the problem lies in the '.js.erb'. Write javascript in separate javascript files (in app/assets/javascripts/) and use JSON to get data from the rails ba
by boundlessdreamz 11y ago
I think the problem lies in the '.js.erb'. Write javascript in separate javascript files (in app/assets/javascripts/) and use JSON to get data from the rails backend.
Have you seen this? http://todomvc.com/ http://todomvc.com/ You can try implementing a backend in Rails for the jquery example. https://github.com/tastejs/todomvc/tree/gh-pages/examples/jquery https://github.com/tastejs/todomvc/tree/gh-pages/examples/jq....
The JS file shows how to organize javascript code - https://github.com/tastejs/todomvc/blob/gh-pages/examples/jquery/js/app.js https://github.com/tastejs/todomvc/blob/gh-pages/examples/jq...
Also unless you really like coffeescript, stick with javascript. If the syntax is bothering you, you can write in ES6 (next version of javascript) which has nicer syntax and use babel to convert to ES5
1. https://gist.github.com/danielgtaylor/0b60c2ed1f069f118562 https://gist.github.com/danielgtaylor/0b60c2ed1f069f118562
2. http://justicen.com/#/posts/74046fea9a4c61477db9 http://justicen.com/#/posts/74046fea9a4c61477db9
- marcamillion 11y agoI hadn't seen todomvc but it doesn't quite address my issues. It still feels too disconnected from where I am. Also, I do write JS in separate JS files - but my understanding is that when you want a response to be in JS, don't you have to use a corresponding `...js.erb` file to handle the action/response? How else would you update the DOM after the action has been completed?
- boundlessdreamz 11y agoYou send the response as json and act upon it. Have a look at this - http://jsbin.com/depuvelixu/edit?html,js,output http://jsbin.com/depuvelixu/edit?html,js,output The json the code fetches is static but it can be served by a rails app. The DOM manipulation gets painful which is the reason people adopt JS frameworks.