I want to reload a partial every 3 seconds on a 'new'-view in my rails app.
我想在rails应用程序的'new'-view上每3秒重新加载一次。
I have this in my new.html.erb
我在new.html.erb中有这个
<h1>Controller#new</h1>
This is my static content
<%= render partial: 'dynamic' %>
More Static content
How do I get this partial reloaded every 3 seconds? Do I have to use unobtrusive javascript for this? How can I achieve this through ujs?
如何每3秒钟重新加载一次?我必须使用不引人注目的JavaScript吗?我怎样才能通过ujs实现这一目标?
1 个解决方案
#1
17
Put partial in div
把div放在div中
<div class="dynamic"><%= render partial: 'dynamic' %></div>
You can do it by using jquery like this
你可以使用像这样的jquery来做到这一点
$(document).ready(
function() {
setInterval(function() {
$('.dynamic').load('/controller_name/action_name');
}, 3000);
});
Now refresh partial in controller action for load new content
现在刷新部分控制器操作以加载新内容
def action_name
render :partial => "directory_name/dynamic"
end
It will sure work.........
它一定会工作.........
#1
17
Put partial in div
把div放在div中
<div class="dynamic"><%= render partial: 'dynamic' %></div>
You can do it by using jquery like this
你可以使用像这样的jquery来做到这一点
$(document).ready(
function() {
setInterval(function() {
$('.dynamic').load('/controller_name/action_name');
}, 3000);
});
Now refresh partial in controller action for load new content
现在刷新部分控制器操作以加载新内容
def action_name
render :partial => "directory_name/dynamic"
end
It will sure work.........
它一定会工作.........