Topic: interaction between jquery and rails?

Hi guys,

I'm a new of Rails. And I still didn't understand the interaction between jquery (or javascript) and rails. For example, I've below jquery:

<% @rails_variable = @rails_variable + 1 %>

Then I view source, I saw "alert(1)", that mean rails already rendered @rails_variable to be set before I click the "test". So whenever I click the "test" link, I'll get the same things.

How can I make the interaction between jquery and rails is more flexible?

Anyway, in my case, I'm trying to make jquery buttons to show next and previous comments. So if you've any idea about this, please give me some advices also.

Thanks so much for your kind helps!