在Rails应用程序重新加载部分应用程序、加载、部分、Rails

由网友(亽野性Ζī浪)分享简介:我想重装的部分每3秒对new'视图在我的Rails应用程序。I want to reload a partial every 3 seconds on a 'new'-view in my rails app.我已经在我的 new.html.erb Controller#newThis is...

我想重装的部分每3秒对new'视图在我的Rails应用程序。

I want to reload a partial every 3 seconds on a 'new'-view in my rails app.

我已经在我的 new.html.erb

<h1>Controller#new</h1>
This is my static content
<%= render partial: 'dynamic' %>
More Static content

我如何得到这部分重载每3秒?我必须用不显眼的JavaScript的呢?我怎样才能做到这一点通过UJS?

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?

推荐答案

把部分的DIV

   <div class="dynamic"><%= render partial: 'dynamic' %></div>

您可以通过使用jquery这样做

You can do it by using jquery like this

       $(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.........

阅读全文

相关推荐

最新文章