Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript on Rails

Just started to experiment with HTML5 features and really like the localStorage.

And now I wonder if it makes sense to create some libraries which make life easier. Something which easily persists objects from the localStorage to the server-DB. Something like a object.findAllByAttribute(Attribute) etc.

So my question is: is there already something out there which helps me to write offline html5 applications? If not, would it make sense or am I thinking the wrong way?

like image 249
rdmueller Avatar asked Feb 25 '11 10:02

rdmueller


People also ask

Does Rails use JavaScript?

Rails uses a technique called "Unobtrusive JavaScript" to handle attaching JavaScript to the DOM. This is generally considered to be a best-practice within the frontend community, but you may occasionally read tutorials that demonstrate other ways. When clicked, the link background will become red.

Where do I put JavaScript code in Rails?

This bit of JS should be put in the file app/assets/javascripts/blogs. js. coffee (CoffeeScript is the default way to create JS for Rails).

Is Ruby on Rails a JS?

Javascript is a client-side coding language that excels at front-end application development. On the other hand, Ruby on Rails is a full-stack framework that is most often used for backend development. It's obvious from this description that they don't compete, but rather complement each other.


2 Answers

backbone.js is a Javascript framework which will help make that task easier. It has support for localStorage as well as sync from server.

http://documentcloud.github.com/backbone/

This is an example application which make use of localStorage.

http://documentcloud.github.com/backbone/docs/todos.html

This uses backbone localStorage adapter.

http://documentcloud.github.com/backbone/docs/backbone-localstorage.html

like image 154
Amitabh Avatar answered Sep 27 '22 16:09

Amitabh


I haven't used it myself but https://github.com/wycats/jquery-offline might be quite a good fit.

Also there is js-model which supports localStorage https://github.com/benpickles/js-model, I have used it and it is very good, I think syncing between localStorage and your server is probably fairly app specific though.

like image 21
Oliver Nightingale Avatar answered Sep 27 '22 15:09

Oliver Nightingale