aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable
diff options
context:
space:
mode:
authorPrathamesh Sonpatki <csonpatki@gmail.com>2016-04-12 22:49:38 +0530
committerPrathamesh Sonpatki <csonpatki@gmail.com>2016-04-12 22:49:38 +0530
commitd0023deb74c8093900f0d703bb5c68eb766e5bdd (patch)
treeac4d9b5457f027774854c66317d53a71fa359fb9 /actioncable
parentdb9bc8097399aab9c866175b12e9e099b6c83ffa (diff)
downloadrails-d0023deb74c8093900f0d703bb5c68eb766e5bdd.tar.gz
rails-d0023deb74c8093900f0d703bb5c68eb766e5bdd.tar.bz2
rails-d0023deb74c8093900f0d703bb5c68eb766e5bdd.zip
Generate `cable.js` file if does not exist when generating channel
- Before this, while generating a channel, we were not creating `cable.js` if it does not already exist. - We have similar code for application mailer here - https://github.com/rails/rails/commit/0b3ae023d27197417541932632055cd6be4810c4. - Based on the comment - https://github.com/rails/rails/issues/24418#issuecomment-205421995.
Diffstat (limited to 'actioncable')
-rw-r--r--actioncable/lib/rails/generators/channel/channel_generator.rb1
-rw-r--r--actioncable/lib/rails/generators/channel/templates/assets/cable.js13
2 files changed, 14 insertions, 0 deletions
diff --git a/actioncable/lib/rails/generators/channel/channel_generator.rb b/actioncable/lib/rails/generators/channel/channel_generator.rb
index d89ab45816..3bcf5f1898 100644
--- a/actioncable/lib/rails/generators/channel/channel_generator.rb
+++ b/actioncable/lib/rails/generators/channel/channel_generator.rb
@@ -13,6 +13,7 @@ module Rails
template "channel.rb", File.join('app/channels', class_path, "#{file_name}_channel.rb")
if options[:assets]
+ template "assets/cable.js", "app/assets/javascripts/cable.js"
template "assets/channel.coffee", File.join('app/assets/javascripts/channels', class_path, "#{file_name}.coffee")
end
diff --git a/actioncable/lib/rails/generators/channel/templates/assets/cable.js b/actioncable/lib/rails/generators/channel/templates/assets/cable.js
new file mode 100644
index 0000000000..71ee1e66de
--- /dev/null
+++ b/actioncable/lib/rails/generators/channel/templates/assets/cable.js
@@ -0,0 +1,13 @@
+// Action Cable provides the framework to deal with WebSockets in Rails.
+// You can generate new channels where WebSocket features live using the rails generate channel command.
+//
+//= require action_cable
+//= require_self
+//= require_tree ./channels
+
+(function() {
+ this.App || (this.App = {});
+
+ App.cable = ActionCable.createConsumer();
+
+}).call(this);