1.下载安装jQuery
从
http://docs.jquery.com/Downloading_jQuery下载最新version的jQuery.
把下载下来的jQuery copy到public/javascripts目录,public/javascripts里面有些默认的JS文件可以delete掉,因为那些是Prototype/Script.aculo.us 的,我们不需要用到的.
2.下载安装JRails
什么是JRails? JRails就是用jQuery替代Prototype/script.aculo.us在Rails做 helpers实现javascript的功能.
安装JRails:
./script/plugin install http://ennerchi.googlecode.com/svn/trunk/plugins/jrails
把JS加到layouts: <%= javascript_include_tag "jquery", "jquery-ui", "jrails" %>
或者<%= javascript_include_tag :all %>
3.修改之前Prototype/script.aculo.us在Rails做helpers实现javascript的功能的一些代码
我们需要把id参数从:id或者'id'改为'#id',例如:
之前的:
<%= observe_field :suggest, :url => { :action => :find_suggestion },
:frequency => 0.25,
:update => :suggest,
:with => 'q'
%>
改为:
<%= observe_field '#suggest', :url => { :action => :find_suggestion },
:frequency => 0.25,
:update => '#suggest',
:with => 'q'
%>
the end