In this project, we will practice CRUD -- but with asynchronous Ajax requests this time.
In the end, this should be a single-page application, and I should be able to perform all actions without leaving the notes#index page.
Use the Faker gem to add 100 notes.
Add a form to create a new note to notes#index.
When clicked, it should remove the note from the db and slideUp the note in the DOM.
When submitted, it should add a new note to the db and slideDown the note in the DOM.
When clicked, it should replace the note with an edit form.
When submitted, it should replace the edit form with the updated note.
Remember, the recipe for Ajaxifying any action is:
- Add the
:remote => trueoption to the link or form helper that you want to Ajaxify. - Add support for
format.jsto the responder block of the action that you want to Ajaxify (if the scaffold didn't already give you arespond_tocall, then add one). - Create a .js.erb view template for the action.
- Write some jQuery in the view template to update the DOM.
- While Ajaxifying, it is often very helpful to create partials if you hadn't already, so that you don't have to manually write a bunch of HTML within JavaScript strings and then have to update markup in two places when it changes. Also, don't forget the
escape_javascript(aliasj) helper method that will remove characters from Ruby strings that are illegal in JavaScript strings.