Complete the chat room application implementation using Ruby on Rails 6 and WebSockets.
WebSocket is actually a protocol that enables bidirectional communication between the client and the server of a web application over a single long living TCP connection.
We are going to build the web application using:
- Ruby: version ruby 2.7.1
- Rails: version 6.0.3.2
$ git clone https://github.com/TanHongIT/chat_room_rails_6
$ cd chat_room_rails_6
$ bundle install
$ yarn install
You must change the appropriate database configuration
Change configuration at "config/database.yml" with Postgresql.
default: &default
adapter: postgresql
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
username: chat_room_rails_6
password: 1234
host: localhost
# tutorial for ubuntu linux:
# sudo -u postgres psql
# create user "chat_room_rails_6" with password '1234';
# create database "chat_room_rails_6" owner "chat_room_rails_6";
development:
<<: *default
database: chat_room_rails_6
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: chat_room_rails_6_test
production:
<<: *default
database: chat_room_rails_6_production
You must change the username, password and database name accordingly!
$ rails db:migrate
We are going to use the redis adapter which is a safe option for production environments unlike the async one.
You first must install redis on your system.
To install it on Ubuntu you just have to execute the following commands in your terminal:
$ sudo apt update
$ sudo apt install redis-server
-
Install redis for Windows 8.1 and previous versions. Go to https://redislabs.com/blog/redis-on-windows-8-1-and-previous-versions/
-
Install redis for Windows 10: https://redislabs.com/blog/redis-on-windows-10/
Now open terminal and run:
redis-server
To check that installation is successful, in your terminal make sure you get a PONG:
$ redis-cli
127.0.0.1:6379> ping
PONG
$ rails s
And now go to http://localhost:3000/
Read more: Chat Room Realtime App With Deno : https://github.com/TanHongIT/Deno-Realtime-Chat-App