http://rorwiki.hellopen.net/index.php?title=HowtosDevelopment
ROR對ajax提供了良好的支持。要使用ajax首先要引入類庫。
1.使用 define_javascript_functions
<html>
?<head>
??<%=define_javascript_functions%>
?</head>
</html>
2.使用 javascript_include_tag
<html>
?<head>
??<%=javascript_include_tag(:defaults)%>
?</head>
</html>
顯示結果:
<html>
?<head>
??<script type="text/javascript" src="/javascripts/prototype.js"></script>
???...
??<script type="text/javascript" src="/javascripts/controls.js"></script>
?</head>
</html>
使用define_javascript_functions和javascript_include_tag(:defaults)有什么區別。
define_javascript_functions粘貼了所有的javascript代碼在視圖上,全部為21k。而
javascript_include_tag使用<script>標記引入javascript文件,如prototype.js, controls.js。
使用javascript_include_tag可以被快速的下載,以后就可以被瀏覽器緩存。這樣就不用每一頁去
下載了。