Adding New RSVPs w/o a Refresh to the Checkins Page

11 views
Skip to first unread message

Steven Leiva

unread,
Dec 28, 2015, 5:25:23 PM12/28/15
to Bridge Troll
Hi Everyone,

I'm working on Issue #388. I'm excited to work on this, as I wanted to work with front-end MV* frameworks for  a while and never found the opportunity / time. Backbone.js seems like a good point to start. I'm running into an issue, but there is a lot of setup information that I must convey in order to properly describe the issue. I've split this post into - SETUP and PROBLEM for easier parsing.

======== SETUP =======
I took some time to figure out how the checkins page (located at: http://localhost:3000/events/1/event_sessions/1/checkins) is rendered, and I am comfortable that I know how it is put together. I'll describe my understanding of the relevant pieces at a high level below:

  1. The user visits the checkins page
  2. The Checkins#index action finds all the rsvps related to that particular session
  3. For each rsvp in step 2, the view renders an HTML snippet to add the rsvp to a table.
  4. A script is ran to finish setting up the page. This set-up includes:
    1. Creating an RsvpSession collection and RsvpSession model.
    2. Initializing polling - i.e., which url to poll, etc.
    3. Updating the RSVP count
    4. Setting a click listener on the toggle_rsvp_session class.
    5. And setting a JavaScript snippet to run when the RsvpSession collection fires a change event.

Lucky for me, the page is already polling the server for update information for updated information, and uses Backbone.js's awesome set function to invoke certain actions whenever the collection changes. Right now, the application is only responding to the collection's change event. Given the current design of the page, I just need to ensure that the application:

  1. Responds to the collection's add event by adding a new RSVP
  2. Updates the RSVP count and checkin count appropriately
  3. And make sure that the new rsvp has the right listeners on it so that it functions like the RSVPs that were on the page when it was first rendered.

======== PROBLEM =======

All of that is a very long-winded way to get to my current problem. On step #1, I need to add RSVPs that are new to the collection. I am trying to do this by creating a handlebars template in app/assets/templates/checkins/rsvp_details.hbs.erb. Unfortunately, this template needs not only RSVP data, but the user attached to that RSVP as well. This was not a problem when the page is originally rendered because you can ActiveRecord associations to pull in the user info in the view. However, a JSON object doesn't have that functionality. How do folks normally handle this problem? Should I return different data for an HTML response vs. a JSON response in the Checkins#index action that includes the user data in a nested JSON object?


I have other questions as well, but first things first.

Steven Leiva

unread,
Dec 28, 2015, 6:17:36 PM12/28/15
to Bridge Troll
I should have known that there would be an easy solution to this (Active Model Serializer) and that I would find it through RailsCasts.com.

I really need a rubber duck. This is the 3rd or 4th time I've done this.

Asheesh Laroia

unread,
Dec 28, 2015, 8:08:04 PM12/28/15
to Steven Leiva, bridge...@googlegroups.com
Steven, for what it's worth, I'm earnestly enjoying your learning process.

You are:

- optimistic

- attempting to learn, and succeeding at learning

- extremely clear in documenting what you've tried

- documenting information about the bridgetroll internals to the list

all of which are a real pleasure to see.

So I for one am enthused about the way you're using this list - namely, attempting things, asking for help, then continuing to try things afterward. I wish I read emails like this every day!

--
You received this message because you are subscribed to the Google Groups "Bridge Troll" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bridge-troll...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Lillie Chilen

unread,
Dec 28, 2015, 9:53:26 PM12/28/15
to Asheesh Laroia, Steven Leiva, bridge...@googlegroups.com
Ditto what Asheesh said. :D :D :D
--
Lillie Chilen
@lilliealbert
('li-lee shuh-'leen)

Steven Leiva

unread,
Dec 28, 2015, 9:58:22 PM12/28/15
to Bridge Troll, ash...@asheesh.org, leiva....@gmail.com
Thank you both for your words of support! I'm learning a ton through contributing!

Steven Leiva

unread,
Dec 30, 2015, 12:21:14 PM12/30/15
to Bridge Troll, ash...@asheesh.org, leiva....@gmail.com
Hi Everyone,

I finally had some  uninterrupted time on a flight yesterday to work on the feature. It is working fine, though I am sure it can be refactored.

At the moment, I am having trouble testing the new code. This is a simple test suite, and I am guessing that the reason it is failing is because the request is that the long-polling step is not being performed. How would I go about testing this feature?

Thanks for any help!

Steven Leiva

unread,
Jan 8, 2016, 10:05:09 AM1/8/16
to Bridge Troll, ash...@asheesh.org, leiva....@gmail.com
Hello everyone, and happy 2016. My apologies for being away for so long. I have been busy with recruiting. But it is now the weekend (or will be soon), and I'd like to finish preparing this pull request. 

As I mentioned, I am stuck on testing. I do not know how to simulate the page's long-polling behavior in a test. My test suite is up on my forked repo here. The problem is that, after I delete an RSVP, the page would normally long-poll the server, and the DOM would update based on any add, remove, or change events triggered by the Backbone model. I do not know how to direct the test suite to "hey, go long-poll the server for info and update yourself". 

Thanks for any help - I'll keep looking into this on my own but if anyone has any ideas, that would be awesome. 
Reply all
Reply to author
Forward
0 new messages