使用link_to:remote-Rails 3的问题

问题描述

|| 我正在使用link_to:remote更新HTML上的
div
元素之一。这只是一个初学者的代码。但是,单击链接不会发生更新。这是代码:
class SampleController < ApplicationController
     def updater
        render :text => Time.now
     end
end
这是list.html.erb:
<script type = \"text/javascript\" src = \"/javascripts/prototype.js\">
<%= link_to \"Hello Testing\",:update => \"test_id\",:url => {:action => \'updater\'},:remote => true
%>
<div id=\"test_id\"></div>
因此,单击链接“ Hello Testing”,浏览器中的URL更改为:
http://localhost:3000/samples?remote=true&update=response_id&url[action]=updater
但是,我尝试设置为当前时间的“ 0”元素在UI上没有发生。这可能是什么问题? 使用以下内容更新了帖子: routes.rb:http://pastebin.com/wmKsa1DD 生成的HTML代码:http://pastebin.com/stU3FpL8 Firebug中的HTML响应:http://pastebin.com/WjsB7zAh 使用
url_for
不会改变行为。     

解决方法

1:还应包括“ 6”文件。在Rails中,它是这样的:
<%= javascript_include_tag :defaults %>
2:我更喜欢对网址使用此命名:
updater_samples_path
[:updater,:samples]
3:您应该显示路线。如果
updater
方法未使用
GET
方法,则应定义它:
<%= link_to \"Hello Testing\",:update => \"test_id\",updater_samples_path,:method => :put,:remote => true %>
4:使用FIREBUG来检查您的AJAX响应。因此,您可以轻松调试您的应用程序。您也可以向我们展示其回应,以便我们更好地了解情况     ,请使用url_for:
<%= link_to \"Hello Testing\",url_for(:action => :updater),:remote => true %>
我不确定100%,但是我不认为:update可以正常工作,因为Rails3现在主要依赖ujs。 用于更新div的\“ rails way \\”看起来像(jquery):
$(\'div#test_id\').bind(\'ajax:complete\',function(event,xhr) {
   $(this).html($.parseJSON(xhr.responseText));
})
    

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...