I want to notify the user if there is a new mail -> so I created a new <div> in which I call a helper function and display the notification using notify js function. It is working correctly as is BUT if I try to run it say every 3 min. it doesn't respond... please provide some guidance.... thanks in advance.
MY CODE:
div in application.html.erb containing the partial for the div
<div class="recentHashMailNotify" ><%= render partial: 'layouts/recentHashMailNotify' %></div>
The JS function to load the controller
<script type="text/javascript">
$(document).ready(function() {setInterval(function() {
$('.recentHashMailNotify').load('/application_controller/recentHashMailNotify');
}, 2000);
});
</script>
The action in the controller
def recentHashMailNotify
render :partial => "layouts/recentHashMailNotify"
end
The partial for the div
<% @recent = notifyHash %>
<% if @recent.any? %>
<% @recent.each do |elem| %>
<script type="text/javascript">
$(document).ready(function(){
$.notify({
icon: 'pe-7s-science',
message: "<%= elem %>"
},{
type: 'info',
delay: 0,
placement:{
from: 'bottom',
align: 'right'
}
});
});
</script>
<% end %>
<%end%>
The notifyHash function
def notifyHash
@imap = Net::IMAP.new(.....)
@imap.login(......)
@imap.select 'folder'
@recent = Array.new
count =0
@imap.uid_search(["RECENT"]).each do |uid|
header = @imap.uid_fetch(uid, "ENVELOPE")[0].attr["ENVELOPE"]
sub = header.subject
count += 1
@recent.push(sub) if sub.include? "#"
end
@recent.push "You have got #{count} new mail" if count != 0
@imap.logout
@imap.disconnect
return @recent
end