Ask A Question


You’re not receiving notifications from this thread.

Multi-User Spreadsheets with ActionCable: Part 5 Discussion

Thanks for the great videos! I should definitely go back and clean up the tutorial so that all the github commits actually line up with the steps, and there's no needless refactoring going on in the middle. I think your last bug with the locks had to do with your renaming of SpreadSheet to Spreadsheet causing the disconnect between those channels to happen again. That's a consistency I should definitely fix in the repo as well.

The final bug you had where the cells would not update, I noticed that happens when you start working on a database that doesn't have the tables pre-created. Basically the stream_from tries to subscribe on a table that doesn't exist and just dies, so your client doesn't receive the updates even though all other things are succeeding. That's a bit of polish that's missing from my nobrainer extension I guess.

Finally let me try a little more explanation of the lock_cell query. The trick is that you have to read `.branch(condition, branch, branch)` as an if statement. So you can read it as:

row = get(location)
result = if row.eq(nil) # if there's no cell at that location yet
{ location: location, lock: id } # create the cell and give you the lock
row.merge( # merge existing row into result
if row.lock.eq(nil) # it's not locked!
{ lock: id } # set the lock to our id
{} # do nothing, so no lock awarded
row.replace(result) # apply the result to the row

Hope this makes sense. The author of nobrainer actually did not like this approach at all, but other solutions would involve adding extra models or general purpose library code I would not immediately grok, so I went with this small opaque query that I sometimes use in SQL as well.


Oh yeah, I realized I made a mistake with the upcase/downcase "S" in spreadsheets and that could definitely do that.

The pre-created tables thing would make sense. It would have taken me too long to figure that one out. :) For the most part, the extension makes everything feel incredibly easy to build an app like this. Changefeeds are cool, but then piping them into ActionCable easily is awesomely simple. Any typical bottlenecks to watch out for there?

Thanks for the description on the lock query! That makes a lot of sense. I figured it was doing something like that, but too long to figure out in a screencast. I think the opaque query is fine in this case for the most part. I'd rather have that one piece I didn't understand to start with, than extra models, etc that make it harder to wrap your head around.

Awesome job on everything and thanks for sharing this tutorial! :D


Just an FYI... the download for this episode has "138" prepended to it instead of "141".

Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 83,603+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.