I followed the each step of above question and here are my changes:
In show.html.erb (http://localhost:3000/posts/24)
<% javascript_tag do %>
$(function() {
setInterval(function(){ $.get("/posts/<%= @post.id %>"); }, 5000);
});
<% end %>
<span id="changed_data">
It should be change after every 5 seconds
</span>
controller class
def show
@post = Post.find(params[:id])
respond_to do |format|
format.js
format.html
end
end
Added a new file
app/views/posts/show.js.erb
$("#changed_data").html("<h2> Changed </h2>");
But it sounds like that javascript_tag
is not calling jquery
method. What am I doing wrong here?
Aucun commentaire:
Enregistrer un commentaire