Skip to content

Saketh1702/collaborative-text-editor-ruby-on-rails

Repository files navigation

Collaborative Text Editor

Install Ruby:

Download Ruby

Install Rails using gem:

gem install rails

Setup Rails Project

Create new Rails project with PostgreSQL

rails new collaborative-editor --database=postgresql --webpack=react

Install additional dependencies:

bundle add redis
bundle add sidekiq

To create test and development databases:

rails db:create

rails db:migrate

Example usage:

# Creating a document
doc = Document.create(content: "Hello", version: 1)

# Inserting text
operation = OpenStruct.new(type: :insert, position: 5, text: " World")
doc.apply_operation(operation)
# Result: "Hello World"

# Deleting text
operation = OpenStruct.new(type: :delete, position: 5, length: 6)
doc.apply_operation(operation)
# Result: "Hello"

Let's set up the WebSocket channel for real-time communication. We'll create this step by step

First, generate the Action Cable channel:

rails generate channel Document

We'll create two main operation types: Insert and Delete for our collaborative text editor

app/operations/insert_operation.rb
app/operations/delete_operation.rb
app/operations/transform_utility.rb

These operations handle:

Inserting text at a specific position
Deleting text from a specific position
Transforming operations when they conflict
Handling overlapping deletions
Maintaining consistency across all clients

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •