Skip to content
Extraits de code Groupes Projets
Valider cc89cd5c rédigé par maxwell's avatar maxwell
Parcourir les fichiers

reload object before send to websocket

parent 10faac2a
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -41,6 +41,7 @@ class Post ...@@ -41,6 +41,7 @@ class Post
protected protected
def send_to_view def send_to_view
self.reload
WebSocket.update_clients(self) WebSocket.update_clients(self)
end end
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
= javascript_include_tag 'jquery142' = javascript_include_tag 'jquery142'
/= javascript_include_tag"http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js" /= javascript_include_tag"http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"
= javascript_include_tag 'rails' = javascript_include_tag 'rails'
= javascript_include_tag 'jquery_form'
- unless request.user_agent.include? "Safari" ||"Chrome" - unless request.user_agent.include? "Safari" ||"Chrome"
= javascript_include_tag 'FABridge' = javascript_include_tag 'FABridge'
= javascript_include_tag 'swfobject' = javascript_include_tag 'swfobject'
...@@ -35,6 +35,19 @@ ...@@ -35,6 +35,19 @@
}, function(){ }, function(){
$(this).fadeTo(80, 1); $(this).fadeTo(80, 1);
}); });
// wait for the DOM to be loaded
// bind 'myForm' and provide a simple callback function
$('#new_status_message').ajaxForm(function() {
alert("Thank you for your comment!");
});
$('#new_bookmark').ajaxForm(function() {
alert("Thank you for your comment!");
});
$('#new_blog').ajaxForm(function() {
alert("Thank you for your comment!");
});
}); });
%body %body
......
%ul %ul
%h3= link_to post.class, object_path(post) %h3= link_to post.class, object_path(post)
- for field in object_fields(post) - for field in object_fields(post)
%li= "#{field}: #{post.attributes[field]}" %li= "#{field}: #{post.attributes[field]}"
\ No newline at end of file
...@@ -8,14 +8,19 @@ module WebSocket ...@@ -8,14 +8,19 @@ module WebSocket
EM.next_tick { EM.next_tick {
EM.add_timer(0.1) do EM.add_timer(0.1) do
@channel = EM::Channel.new @channel = EM::Channel.new
@view = ActionView::Base.new(ActionController::Base.view_paths, {})
class << @view
include ApplicationHelper
include Rails.application.routes.url_helpers
end
end end
EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 8080, :debug => true) do |ws| EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 8080) do |ws|
ws.onopen { ws.onopen {
sid = @channel.subscribe { |msg| ws.send msg } sid = @channel.subscribe { |msg| ws.send msg }
ws.onmessage { |msg| ws.onmessage { |msg|
@channel.push "#{msg}" @channel.push msg
} }
ws.onclose { ws.onclose {
...@@ -27,12 +32,8 @@ module WebSocket ...@@ -27,12 +32,8 @@ module WebSocket
} }
#this should get folded into message queue i think? #this should get folded into message queue i think?
def self.update_clients(object) def self.update_clients(object)
view = ActionView::Base.new(ActionController::Base.view_paths, {})
class << view n = @view.render(:partial => @view.type_partial(object), :locals => {:post => object})
include ApplicationHelper
include Rails.application.routes.url_helpers
end
n = view.render(:partial =>view.type_partial(object), :locals => {:post => object})
@channel.push(n) if @channel @channel.push(n) if @channel
end end
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter