reload object before send to websocket
This commit is contained in:
parent
10faac2a86
commit
cc89cd5cda
4 changed files with 25 additions and 11 deletions
|
|
@ -41,6 +41,7 @@ class Post
|
|||
protected
|
||||
|
||||
def send_to_view
|
||||
self.reload
|
||||
WebSocket.update_clients(self)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
= javascript_include_tag 'jquery142'
|
||||
/= javascript_include_tag"http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"
|
||||
= javascript_include_tag 'rails'
|
||||
|
||||
= javascript_include_tag 'jquery_form'
|
||||
- unless request.user_agent.include? "Safari" ||"Chrome"
|
||||
= javascript_include_tag 'FABridge'
|
||||
= javascript_include_tag 'swfobject'
|
||||
|
|
@ -35,6 +35,19 @@
|
|||
}, function(){
|
||||
$(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
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
%ul
|
||||
%h3= link_to post.class, object_path(post)
|
||||
- for field in object_fields(post)
|
||||
%li= "#{field}: #{post.attributes[field]}"
|
||||
|
||||
%li= "#{field}: #{post.attributes[field]}"
|
||||
|
|
@ -8,14 +8,19 @@ module WebSocket
|
|||
EM.next_tick {
|
||||
EM.add_timer(0.1) do
|
||||
@channel = EM::Channel.new
|
||||
@view = ActionView::Base.new(ActionController::Base.view_paths, {})
|
||||
class << @view
|
||||
include ApplicationHelper
|
||||
include Rails.application.routes.url_helpers
|
||||
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 {
|
||||
sid = @channel.subscribe { |msg| ws.send msg }
|
||||
|
||||
ws.onmessage { |msg|
|
||||
@channel.push "#{msg}"
|
||||
@channel.push msg
|
||||
}
|
||||
|
||||
ws.onclose {
|
||||
|
|
@ -27,12 +32,8 @@ module WebSocket
|
|||
}
|
||||
#this should get folded into message queue i think?
|
||||
def self.update_clients(object)
|
||||
view = ActionView::Base.new(ActionController::Base.view_paths, {})
|
||||
class << view
|
||||
include ApplicationHelper
|
||||
include Rails.application.routes.url_helpers
|
||||
end
|
||||
n = view.render(:partial =>view.type_partial(object), :locals => {:post => object})
|
||||
|
||||
n = @view.render(:partial => @view.type_partial(object), :locals => {:post => object})
|
||||
@channel.push(n) if @channel
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue