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:

<script>
$("#test").click(function(){
<% @rails_variable = @rails_variable + 1 %>
alert(@rails_variable);
});
</script>

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!

Re: interaction between jquery and rails?

There are a few reasons I switched over to jQuery, and no I was not drinking the Kool-aid of joining the boat of the bigger players.

    The syntax made sense and was so much easier to write.
    It was faster at its traversing of the DOM compared to other libraries. I didn’t even try to use YUI, while it’s very hefty in what it does, it is extremely slow and seems to reek of code bloat.
    It’s continuously developed on as the community seems a lot stronger than that of Prototype’s.

Last edited by Kenank (2013-02-05 08:25:18)