【发布时间】:2012-12-29 20:48:11
【问题描述】:
我有很多模型。现在我想只向特定的控制器和方法展示 JavaScript。
例如,如果我有这样的代码并且只想在 communities/show 中显示它
我应该将其粘贴到 view/communities/show.html.erb 的头部吗?
还是有更聪明的方法来管理这类事情?
显然,如果我把它放在显示文件的头部看起来很丑,因为 JavaScript 总是应该放在 标记中。
<%= javascript_tag do %>
jQuery(document).ready(function () {
refreshPartial();
setInterval(refreshPartial, 5000)
});
function refreshPartial() {
$.ajax({
url: "<%= community_path %>/refresh_part",
type: "GET",
dataType: "script",
});
}
<% end %>
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 jquery