views:

29

answers:

1

*I was wondering if i could do all these in javascript, as opposed to having rails helpers

In my application, there are several types of "if-else" UI cases. This is a fairly common scenario, and i wonder if anyone has a tidy way to do these?

EG 1) There might be several types of links with the same behavior: "upvote", etc.

If it is the user's own article, i do not want it to be passed to the server, but pop up a dialog box

EG 2) There might be a several links called "follow", "become a fan", etc

If the user already have done the given action before, it should be a text "followed" instead of a link.

A: 

Normally you'd use helpers for this. You write helpers called, based on your examples, upvote_button (which might take a user as a parameter) or follow_button (where this one might take true/false for already-following/not-following.

If you can be more specific as to what you need, I can probably be more specific in my answer.

thenduks
I understand, i was hoping that i did not need to specify 2 sets of behavior, one in the helper, and one in the javascript. =)
ming yeow
Should still be fine. In the helper you give different classes (or other attribute) to the different types of results and hook into that via javascript like you were already going to have to.
thenduks