4 ms·
This tutorial is awesome! I love the tone and how it knows EXACTLY who it is written for. This may be a bit late, but I would LOVE for someone to do this for J
by marcamillion 11y ago
This tutorial is awesome! I love the tone and how it knows EXACTLY who it is written for.
This may be a bit late, but I would LOVE for someone to do this for JS in a Rails App (or even CoffeeScript). I am desparately searching for good tutorials for people that are "borderline-decent" at jQuery but are Rails devs. I can't find any.
I understand, in theory, how to render some JS on a view and all this good stuff - but once you go into creating a UI that feels like a modern UI with lots of lil AJAXy elements...it can become a pain REAL quick with a bunch of `...js.erb`s all over the place with no seeming pattern to them.
So I would love if someone had a tutorial just like this, for how to create a simple and sexy app that looks like an Angular/Ember app but just using CoffeeScript/jQuery/vanilla JS.
Anyone know of any such thing?
- boundlessdreamz 11y agoI 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.