提交 28035db1 编写于 作者: D David Heinemeier Hansson

Generate all the ApplicationCable stubs by default, like all other Application* stubs

上级 6357437d
......@@ -10,12 +10,6 @@ class ChannelGenerator < NamedBase
def create_channel_file
template "channel.rb", File.join('app/channels', class_path, "#{file_name}_channel.rb")
template "assets/channel.coffee", File.join('app/assets/javascripts/channels', class_path, "#{file_name}.coffee")
if self.behavior == :invoke
template "application_cable/connection.rb", 'app/channels/application_cable/connection.rb'
template "application_cable/channel.rb", 'app/channels/application_cable/channel.rb'
template "assets/consumer.coffee", 'app/assets/javascripts/cable.coffee'
end
end
protected
......
......@@ -57,6 +57,8 @@ def app
directory 'app'
keep_file 'app/assets/images'
keep_file 'app/assets/javascripts/channels'
keep_file 'app/mailers'
keep_file 'app/models'
......
......@@ -2,5 +2,6 @@
#= require_self
#= require_tree ./channels
@App ||= {}
App.cable = ActionCable.createConsumer()
# Turn on the cable connection by removing the comments from the statements below:
# @App ||= {}
# App.cable = ActionCable.createConsumer()
# Be sure to restart your server when you modify this file. Action Cable runs in an EventMachine loop that does not support auto reloading.
module ApplicationCable
class Channel < ActionCable::Channel::Base
# Logic shared between all channels
end
end
\ No newline at end of file
end
# Be sure to restart your server when you modify this file. Action Cable runs in an EventMachine loop that does not support auto reloading.
module ApplicationCable
class Connection < ActionCable::Connection::Base
# identified_by :current_user
#
# def connect
# self.current_user = find_verified_user
# end
#
# protected
# def find_verified_user
# if current_user = authenticate_with_cookies
# current_user
# else
# reject_unauthorized_connection
# end
# end
#
# def authenticate_with_cookies
# User.find(cookies.signed[:user_id])
# end
end
end
......@@ -2,5 +2,5 @@
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
# Serve websocket cable requests in-process
mount ActionCable.server => '/cable' if defined?(ApplicationCable)
mount ActionCable.server => '/cable'
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册