1.建立一個將被rjs模板更新的視圖.
??? <h1 id='header'>RJS Template Test</h1>
??? <ul id='list'>
????? <li>Dog</li>
????? <li>Cat</li>
????? <li>Mouse</li>
??? </ul>
??? <%= link_to_remote("Add a fox",
????????? :url =>{ :action => :add }) %>
?????????
確定你引入了javascript類庫
<%= javascript_include_tag :defaults %>
2.在link_to_remote指向的控制器中加入一個方法
def add
end
3.rails將尋找擴展名為.rjs,.rhtml,rxml的模板,因此建立一個名為
add.rjs的文件,并輸入:
page.insert_html :bottom, 'list',
???????????????? content_tag("li", "Fox")
page.visual_effect :highlight, 'list', :duration => 3
page.replace_html 'header',
????????????????? 'RJS Template Test Complete!'
?????????????????
?????????????????
4.啟動服務(wù)器,在瀏覽器頁面點擊"Add a fox",就可以看到效果了.