我有一個控制器:簡單的Ajax例子
class QuestionsController < ApplicationController
def hello
puts "====================!!!==================="
@hello = "hey"
"some"
end
def test
end
test.rhtml:
<%= javascript_include_tag :defaults %>
<br/>
Click this link to show the current
<br/>
<%= link_to "hello",
{ :controller => "questions", :action => "hello" },
:update => 'time_div',
:remote => true %>.
<br/>
<div id='time_div'>
...
</div>
當我點擊 '你好' 鏈接我看到你好()方法被調用,但html頁面保持不變。爲什麼?
如何更改HTML頁面的代碼?
這裏生成HTML頁面:
<!DOCTYPE html>
<html>
<head>
<title>Stack</title>
<script src="/javascripts/jquery.js?1286229922" type="text/javascript"></script>
<script src="/javascripts/jquery-ujs.js?1286229922" type="text/javascript"></script>
<meta name="csrf-param" content="authenticity_token"/>
<meta name="csrf-token" content="UKPX1dNCZhyTk8u71hR9KaUmufIire7Rhvg8t7cRSlM="/>
</head>
<body>
<br/>
Click this link to show the current
<br/>
<a href="https://stackoverflow.com/questions/hello" data-remote="true">hello</a>
<br/>
<div id='time_div'>
...
</div>
</body>
</html>
您正在使用哪個版本的導軌? – Ashish 2011-04-05 10:16:40
http://stackoverflow.com/questions/5511787/rails-2-to-rails-3-using-link-to-instead-of-link-to-remote-including-remote-an – Ciryon 2011-04-05 10:18:55
@Ashish:Rails3 – demas 2011-04-05 10:20:52