First Ajax Project
This project is a simple secret sharing project. I've written two
Secret. I've also built
SessionsController to do login for you.
/users/123/secrets/new form. Use
form_for. You'll need to
create a nested route.
Phase II: Add friendships
Friendship model to join
User. Friendship is
one-way in this application. Write a simple
(the only action needed is
create, I think).
/users page, list all users, and add a
friend button for
each. Make this button remote. When clicked, change the button text to
ajax:before), and disable. On
change text to "Friended".
When the template is first rendered, appropriately grey-out the button if the user has already been friended.
Phase III: Remove friendships
All things must end; you grow apart. You're still proud of your friend, but you don't stay in touch anymore.
Add a second button, to unfriend a user. You'll need a
You now want to the unfriend button to appear when you are friends, and the friend button to appear when you are not. The cleanest way to do this is to:
- Writeboth buttons, display them both.
- Place the two buttons in a div or span, give this a CSS
friend_buttons. Likewise, give your buttons classes of
- If we are friends, set a second class on your div:
friended. Otherwise, set
- Write a CSS rule so that
visible: false. Do likewise for
- Lastly, your
ajax:successmethod needs only to swap a class (see