samedi 29 novembre 2014

jQuery redirect not working with Rails each-loop


I have a Rails site where creating a new post responds to JavaScript.


I'm also using the private_pub gem and trigger a push message after creating the post.


The user should be redirected to the post after it has been created.


This is the content of create.js.erb:



<%= @users.each do |user| %>
<% publish_to "/user/#{user.id}" do %>
$("#messages").prepend("<%= j render(@message) %>");
<% end %>
<% end %>

var url = "/posts/<%= j @post.id %>";
$(location).attr('href',url);


The push message is working fine, but the user is not redirected.


If I remove the each-loop, the redirection works. Any other code is not influenced by the loop at all, also the position in the file doesn't change anything. I've tried many different approaches but haven't found any solution.





Aucun commentaire:

Enregistrer un commentaire