Forum: Ruby on Rails Initial load time when periodically_call_remote

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
451c775e5b876624750923a403850b0b?d=identicon&s=25 Sergey Podlesnyi (sergeypo)
on 2006-04-19 16:30
When I do periodically_call_remote with e.g. :frequency => 30
after initial page load I have to wait 30 seconds until this partial
renders first time. Does anybody know how to make ROR to render partial
on web page load, and then start periodic calls every 30 seconds? I
tried to put

<div id='mydiv'><%= render(:partial, :action=>'myaction') %></div>
<% periodically_call_remote(:update=>'mydiv',
:url=>{:action=>'myaction'}, frequency=>30) %>

but it does not work somehow...

Please help!
4daf0b71d5d9a3882e583c0e72eaf5dc?d=identicon&s=25 Alan Francis (Guest)
on 2006-04-19 16:37
sergey podlesnyi wrote:
> When I do periodically_call_remote with e.g. :frequency => 30
> after initial page load I have to wait 30 seconds until this partial
> renders first time. Does anybody know how to make ROR to render partial
> on web page load, and then start periodic calls every 30 seconds? I
> tried to put
>
> <div id='mydiv'><%= render(:partial, :action=>'myaction') %></div>
> <% periodically_call_remote(:update=>'mydiv',
> :url=>{:action=>'myaction'}, frequency=>30) %>
>
> but it does not work somehow...
>
> Please help!

:partial will be looking for a view/_partial, which isn't wnat you want,
as you're trying to render an action.  Does render :action =>'myaction'
work (without the partial)

Alan
451c775e5b876624750923a403850b0b?d=identicon&s=25 Sergey Podlesnyi (sergeypo)
on 2006-04-19 16:41
>
> :partial will be looking for a view/_partial, which isn't wnat you want,
> as you're trying to render an action.  Does render :action =>'myaction'
> work (without the partial)
>
> Alan

will try that.. I guess I tried before but it did not find template,
while it finds template for periodic calls.
41e1579600683eed6c00af9a425268e6?d=identicon&s=25 Edward Frederick (Guest)
on 2006-04-19 16:41
(Received via mailing list)
Hi,

Yeah, your <%= render(:partial, :action=>'myaction') %> is broken.

If you want to render an entire action, you need to render as a
component.

However, this is probably not what you should need to do. Look into
extracting partials, etc.

Ed
4daf0b71d5d9a3882e583c0e72eaf5dc?d=identicon&s=25 Alan Francis (Guest)
on 2006-04-19 17:08
sergey podlesnyi wrote:
>>
>> :partial will be looking for a view/_partial, which isn't wnat you want,
>> as you're trying to render an action.  Does render :action =>'myaction'
>> work (without the partial)
>>
>> Alan
>
> will try that.. I guess I tried before but it did not find template,
> while it finds template for periodic calls.

Do you have a views/mycontroller/myaction.rhtml file ?

Can you paste the source for 'myaction' ?

Alan
451c775e5b876624750923a403850b0b?d=identicon&s=25 Sergey Podlesnyi (sergeypo)
on 2006-04-19 17:23
>
> Do you have a views/mycontroller/myaction.rhtml file ?
>
> Can you paste the source for 'myaction' ?
>
> Alan

Here it is:

<% @alarms.each do |a| %>
  <tr><td><%= a.start_time -%></td>
  <td><%= a.message -%></td></tr>
<% end %>
4daf0b71d5d9a3882e583c0e72eaf5dc?d=identicon&s=25 Alan Francis (Guest)
on 2006-04-19 17:34
sergey podlesnyi wrote:
>>
>> Do you have a views/mycontroller/myaction.rhtml file ?
>>
>> Can you paste the source for 'myaction' ?
>>
>> Alan
>
> Here it is:
>
> <% @alarms.each do |a| %>
>   <tr><td><%= a.start_time -%></td>
>   <td><%= a.message -%></td></tr>
> <% end %>

Great.  and the controller method ?

A.
451c775e5b876624750923a403850b0b?d=identicon&s=25 Sergey Podlesnyi (sergeypo)
on 2006-04-19 18:08
Alan Francis wrote:
> sergey podlesnyi wrote:
>>>
>>> Do you have a views/mycontroller/myaction.rhtml file ?
>>>
>>> Can you paste the source for 'myaction' ?
>>>
>>> Alan
>>
>> Here it is:
>>
>> <% @alarms.each do |a| %>
>>   <tr><td><%= a.start_time -%></td>
>>   <td><%= a.message -%></td></tr>
>> <% end %>
>
> Great.  and the controller method ?
>
> A.

def update_alarms
  @alarms = ...
  render(:layout -> false)
end
451c775e5b876624750923a403850b0b?d=identicon&s=25 Sergey Podlesnyi (sergeypo)
on 2006-04-19 18:15
And here is how it works now, and takes 30 seconds before it appears on
web page:

<div id='mydiv'>&nbsp;</div>
<% periodically_call_remote(:update=>'mydiv',
:url=>{:action=>'update_alarms'}, frequency=>30) %>
Ad7805c9fcc1f13efc6ed11251a6c4d2?d=identicon&s=25 Alex Young (Guest)
on 2006-04-19 18:27
(Received via mailing list)
sergey podlesnyi wrote:
> And here is how it works now, and takes 30 seconds before it appears on
> web page:
>
> <div id='mydiv'>&nbsp;</div>
> <% periodically_call_remote(:update=>'mydiv',
> :url=>{:action=>'update_alarms'}, frequency=>30) %>
The way I do it is to call a separate function that does the same update
call in the window.onload() handler, so there's basically an extra AJAX
call immediately.  Not hugely efficient, but it works...
This topic is locked and can not be replied to.