【发布时间】:2010-11-20 08:40:17
【问题描述】:
我有一个奇怪的问题,JQuery 正在为 link_to 方法创建两个 AJAX 请求。我正在为 UJS 开发一个带有 JQuery 的 Rails 3 应用程序。我有一个切换链接,可以在“关注”和“取消关注”之间切换
我的链接如下:
<span id="follow_link">
<a href="/tfollow_artist?id=8103103" data-method="post" data-remote="true" id="follow_artist" rel="nofollow">Unfollow</a>
</span>
我的控制器是这样设置的:
def tfollow_artist
@artist = Artist.find(params[:id])
if current_user.following?(@artist)
current_user.stop_following(@artist)
else
current_user.follow(@artist)
end
end
最终将 js 渲染为:
$('#follow_link').html('<%= escape_javascript(render :partial => "follow") %>');
这基本上用相同的 URL 替换了 '... 的 html 内容,只是文本不同。例如,上面现在将呈现为:
<span id="follow_link">
<a href="/tfollow_artist?id=8103103" data-method="post" data-remote="true" id="follow_artist" rel="nofollow">Follow</a>
</span>
但是,这会导致 JQuery 发出两个 AJAX 请求。
谁能看出这里出了什么问题?
我正在使用“jquery-rails”gem,它将最新的 jquery-ujs 文件复制到我的应用程序中。 jQuery版本是1.4.3
【问题讨论】:
-
即使我面临这个错误.. 任何解决方案?
-
这里有同样的问题。仍在寻找解决方案。
-
同上这个问题..你有没有想过这个问题?
-
也面临同样的问题... jquery-rails 1.0.16版。
标签: jquery ruby-on-rails-3 ujs