yrby

Example

A record-backed editor

Open this page in two windows and type in either one. Rails saves the document to its database, and the button below reads it back in Ruby.

Everyone who visits this page edits the same document, and it's cleared after a day with no activity. Don't type anything private.

Connecting…

Read back from Rails

Type something, then select “Read saved text”.
doc = @document.collaborative_document(:body).y_doc
doc.read_text("content")

How it's wired

The view renders collaborative_document_tag. Once the document syncs, the page's script attaches CodeMirror to it. When the lease's abort signal fires, the script removes CodeMirror again. The document session keeps any edits the server hasn't confirmed yet, so removing the editor doesn't lose them.

This page runs the published gems and client. The site adds the same limits to the gem's channel that the public demos use. In your own app, check that the user can edit the record before you render the tag.

Getting started · The JavaScript client