Step 5 Storing a game in the backend - Thewessen/tic-tac-toe_ruby_backend GitHub Wiki

Today I shouldn't be working on this project anymore. But I really like what I've achieved so far. All the new things I've learned. And the progression on my tic-tac-toe game. So I decided it's time to finish it, so I can dedicate the time left learning more about RoR and Emberjs internals.

Allowing patch requests

The day starts with another CORS problem. I thouged Rack-Cors gem was in place, but I didn't configured it to allow cross-domain patch request. So an easy fix here.

Instead of using jbuilder for customizing the JSON:API response, I found their is a better solution: active_model_serializer using json-api. Just define the attributes and relations of the model in the serializer and you are done! Now the json: is rendered correctly in the response... Now patch requests work like a charm! Cool!

Very interesting bug

When iterating over my initial boardstate array, creating the rows and cells for the board, the cell value isn't bound as an attribute too the component. So after declaring a winner, the board template get's rerendered and all my value's are gone. The rows still contain the correct (marked) data. So I would think, after a rerender, the cell have that data as whell. I was wrong.

For some reason I thouged it had something to do with mutability. After searching the internet for a emberjs helper function that would convert all array elements too observable object (which I thoughed an EmberArray would do...) I couldn't find anything close. So I desided to map all cell array elements to objects { value: ...} .

Now for the interesting part. After doing so, the problem went away. No big deal you would say?? Whell, the game logic (which I didn't updated yet), still continued to function as whell! How is this possible?? It is now woring with objects containing a value property instead of string... Mind blowing.

Oke, nvm, it kept working because I changed the values too strings after clicking a cell....

TODO: Utilizing EmberObjects for the purpose??

⚠️ **GitHub.com Fallback** ⚠️