I'm working on chating
module. For that I've used private_pub gem
. In this module I have made three channels, but I can't mention all those here, because it'll show a very, very large page. So let's stick to one channel.
I click on a link having channel "<%= subscribe_to "/conversations/send_invitation" %>"
and then ajax
works and goes to "conversations/send_invitation"
(only once - which is ok) and in my "/conversations/send_invitation"
I have
def send_invitation
@conversation = Conversation.new(conversation_params)
respond_to do |format|
format.js { render :layout => false }
format.html
end
end
and then in my send_invitation.js.erb
file I've the following
<% publish_to "/conversations/send_invitation" do %>
var recipient_id = "<%=@conversation.recipient.id %>";
var current_temp_user = $("#current_temp_user").val();
if(recipient_id == current_temp_user){
console.log('here')
$("#invitation_div").html("<%=j(render :partial => '/restaurants/invitation')%>");
card_modal = $('#invitation_card').modal();
card_modal.modal('show');
}
<% end %>
Here is my application.js
file
//= require jquery
// require jquery-ui
//= require jquery_ujs
// require turbolinks
//= require bootstrap
//= require jquery.raty
//= require private_pub
//= require_tree .
And the modal displays at recipient side
(which is good).
Now the problem is that I can see two modal
with the same id
in my firefox console/html
. And the buttons
for closing/submit
the modal
also stopped working. Also the console.log
in my send_invitation.js.erb
file showed two time the console.log
result, so it's clear that js.erb
file is executing two times. But the point to note is that ajax
ran one time only. I've wasted couple of hours on it and found only This link which also didn't work for me, because when I remove either jquery.js
or jquery_ujs.js
it gives me errors