[LRUG] Best practices for javascript in Rails apps

Aanand Prasad aanand.prasad at gmail.com
Wed Jul 17 05:31:06 PDT 2013


I've found Knockout.js (http://knockoutjs.com/documentation/introduction.html) to be a great just-the-bindings-please library, as long as you're fine with its <span data-bind="text: variableName"/> style. It strikes me that it'd make a good fit for a mostly server-side app: populate your HTML with data *and* binding attributes, and then hijack it with Knockout as and when you need to update stuff. 

I'm an advocate of putting your JS in modules and explicitly importing them, but I don't know what the current best tool for that is. browserify (http://browserify.org/), require.js (http://requirejs.org/) and Square's ES6 module transpiler (http://square.github.io/es6-module-transpiler/) are all relevant.



On Wednesday, 17 July 2013 at 13:13, Tim Cowlishaw wrote:

> Hi all,
> 
> I've just finished working on the first rails app I've started from
> scratch in ages, and, took the opportunity to apply some of the ideas
> from Matt Wynne's Hexagonal Rails talk and Avdi Grimm's Objects on
> Rails book, in the process.
> 
> I've been really happy with the result - I've been able to make
> changes with more confidence, and ship new features faster than I have
> taking a more rails-y approach to application architecture, and my
> test coverage is vastly better.
> 
> Whoever, there's a rather nasty skeleton in the
> "app/assets/javascript" closet in my app, as, while I'm aware of the
> proliferation of javascript testing frameworks and tools, and
> libraries for doing client-side models, data-binding, etc, I'm really
> not sure how best to structure my javascript code in order to take
> advantage of them (apart from throwing out the idea of server
> generated views entirely, and writing a thick-client js app which
> talks to an API, which I'm not keen on, as I'm a boring old
> stick-in-the-mud who likes things on the web to have proper URLs)
> 
> Therefore, has anyone got any tips or tricks for writing maintainable,
> testable, well-factored javascript as part of a rails application
> which has reasonably complex client-side behaviour, but isn't a
> one-page app? Links to talks / blogposts / example codebases also
> gratefully appreciated!
> 
> Cheers,
> 
> Tim
> _______________________________________________
> Chat mailing list
> Chat at lists.lrug.org (mailto:Chat at lists.lrug.org)
> http://lists.lrug.org/listinfo.cgi/chat-lrug.org
> 
> 


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20130717/02716fb2/attachment.html>


More information about the Chat mailing list