开发者

Using Javascript on Ruby on rails

开发者 https://www.devze.com 2023-03-04 17:08 出处:网络
I am trying to use update some calculations everytime a person modifies a text field. I have many question about how to know the id text field, how to store it in a variable, etc. I am开发者_如何转开发

I am trying to use update some calculations everytime a person modifies a text field. I have many question about how to know the id text field, how to store it in a variable, etc. I am开发者_如何转开发 a newbie with ruby and javascript and there are many questions. Could you please tell me where I can find more information that explains step by step how to proceed with this?

Thank you very much.


I highly recommend using jQuery with Ruby on Rails... it makes this sort of thing much easier, and is going to be the standard as of the next version (3.1).

In jQuery, you do something like:

$('#my_field').change(function() {
  $('#result').val(function() {
    do something...
  });
});

And you can use a js.erb template to embed Ruby in the JS to get data from the controller. Ryan Bates' Railscasts series has several examples of using Javascript in RoR for dynamic content.

Also, NetTuts+ has this tutorial for using Unobtrusive JavaScript in Rails 3.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号