Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 4 and ActionCable

I am building a real time chat into a rails 4 application. It seems ActionCable is the tool for this kind of job.

Is it possible to use ActionCable in rails 4 or do I have update to rails 5?

I cannot find any introduction for ActionCable with rails 4.

like image 857
DenicioCode Avatar asked Mar 21 '16 15:03

DenicioCode


People also ask

What is Rails ActionCable?

1 What is Action Cable? Action Cable seamlessly integrates WebSockets with the rest of your Rails application. It allows for real-time features to be written in Ruby in the same style and form as the rest of your Rails application, while still being performant and scalable.

What is AnyCable?

AnyCable allows you to use any WebSocket server (written in any language) as a replacement for your Ruby server (such as Faye, Action Cable, etc). AnyCable uses the same protocol as ActionCable, so you can use its JavaScript client without any monkey-patching.

What is WebSocket in rails?

WebSocket connections enable simultaneous and bidirectional communication, allowing both client and server to send messages at any time through the channel. Another advantage of using WebSockets is once you establish the connection you don't need to exchange much metadata (http headers).

How do you test an action cable?

Testing Action Cable To test this connection class, we can use connect method to simulate a client server connection and then test the state of connection is as expected. The connection object is available in the test.


2 Answers

ActionCable is just a rails-5 way to handle websockets. For current rails there is Faye(https://github.com/faye) with multiple wrappers like private-pub and faye-rails.

Also you do not have to write the websocket handler in ruby at all

like image 200
Vasfed Avatar answered Sep 21 '22 16:09

Vasfed


Rails, in and of itself, is just a collection of various Rubygems. ActionCable is just a new gem added to the collection with Rails 5. You can install ActionCable by itself via your Gemfile:

gem 'actioncable', '~> 5.0.0.beta3'

Then just go about setting it up. Here is a decent write up on it:

http://www.thegreatcodeadventure.com/rails-5-preview-action-cable/

like image 20
tagCincy Avatar answered Sep 19 '22 16:09

tagCincy