I want to know how a part of the webpage (data obtained from
database) can be refreshed at periodic intervals(say 5 sec).
I have tried periodically_call_remote() method.But it is not working
for me.
<% periodically_call_remote(:url => { :action =>
:show_readings_for_station },
:frequency => 5, :update => "reading_list")%>
<div id="reading_list">
#my code here which obtains data from database
</div>
show_readings_for_station is a method in the controller.....
I want to know how a part of the webpage (data obtained from
database) can be refreshed at periodic intervals(say 5 sec).
I have tried periodically_call_remote() method.But it is not working
for me.
<% periodically_call_remote(:url => { :action =>
:show_readings_for_station },
:frequency => 5, :update => "reading_list")%>
<div id="reading_list">
#my code here which obtains data from database
</div>
show_readings_for_station is a method in the controller.....
Hai Robert,
Thanks for your help.I have done what you have told me.But the problem
is it refreshes only for the first time and shows some RJSerror on the
webpage.
readings controller
def show_current_readings
@range=ConfigureParameter.find(:all)
if (params[:state] =="")
@readings = CurrentReading.find(:all)
else
stations = Station.find_all_by_state(params[:state])
@readings=
CurrentReading.find_all_by_station_id(stations,:order=>"station_id")
end
render :update do |page|
page.replace_html :current_reading,
:partial=>'current_readings_list'
end
end
You are mentioning :update attribute in the ajax call, so in the responding action you do not need to replace the content of the div. Rails will automatically update it.
use following code in your controller
render :partial=>'current_readings_list'
or the second solution is just remove the :update attribute from the ajax call it will run properly.
Sending name of the div - “current_reading” as the :update option in the ajax call is enough to automatically replace the contents. No need for explicitly calling replace_html in the action.
However if you want to use replace_html in your action…
do not send <%= periodically_call_remote(:url => { :action=> :show_current_readings
}, :frequency => 5, :update =>“current_reading”)%>
I hav looked into the development.log file.I understood that the
problem as in "_current_readings_list" it is not getting the id
parameter based on which it has to display the readings.I dont know
whether i am correct or not.
I am attaching the development.log file.
controller
def show_readings_for_station
@range=ConfigureParameter.find(:all)
if (params[:state] =="")
@readings = CurrentReading.find(:all)
else
stations = Station.find_all_by_state(params[:state])
@readings = CurrentReading.find_all_by_station_id(stations,
:order=>"station_id")
end
respond_to do |format|
format.js
end #End of respond_to do block
end #End of action show_readings_for_station
def show_current_readings
@range=ConfigureParameter.find(:all)
if (params[:state] =="")
@readings = CurrentReading.find(:all)
else
stations = Station.find_all_by_state(params[:state])
@readings = CurrentReading.find_all_by_station_id(stations,
:order=>"station_id")
end
render :update do |page|
page.replace_html :current_reading,
:partial=>'current_readings_list'
page.visual_effect :highlight, 'current_reading'
end
end
Can you plz tell me how can i get the id of the selected element in
select tag to the action "show_current_readings"? If i am wrong plz do
correct me..
Thank you soooooooooo much Nitin. Your thing has solved my problem....
Now i am getting the id of the selected state to the
"periodically_call_remote()"
Thank you Bala for giving so much of help....
Thank you all.....