So, it’s finally time for another project, this time working with Sinatra & Activerecord. Mostly focusing on databases, tables, and relationships the basis for my project came to me damn near instantly. No wasting time scouring the web for inspiration this time! Seeing as I have a fairly significant history creating and developing stories independently, (never cared for outside validation/influence/help, despite being confident enough to have multiple stories published if me and my partner gave a damn too) I knew instantly that I wanted an app to help build and keep track of there stories, characters, and events as they develop them. I decided to name this app Writers Block…I have absolutely no idea if that name is already copyrighted for something similar already, but damn did I think it was cool!
**Day 1:** Pretty basic stuff here, snagged the corneal gem to help me get my skeleton file structure and proceeded to build my tables & models. I set it up with 4 different models, although for the purpose of this project I only need to get my user & story classes functional. I did end up spending more time a the conceptualizing than I had originally thought, so I didn't get a lot done overall. Also I started my project on break week, so I took the extra time as a means to set smaller daily goals to avoid fatigue.
**Day 2:** Designed a couple of simplistic views to test against while I set up my controllers. Built the application (really just added a couple of helpers and enabled sessions) and the user controller. At this point in the project I had so many issues that simultaneously messed eachother up I decided to turn off sessions for the time being. This led to a number of issues come **Day 4** but I couldn't make real progress and something had to give. The important thing was I got my signup and login pages sorted out and could proceed to my story controller the next day.
**Day 3:** Story controller time, the heart of the CRUD part of the project. Once again, as I initially based it off my 'Fwitter' lab, I would run into several issues throughout this project. But for today, building my '/stories' landing page after logging in and creating a new story (title, genre, synopsis) was my goal. I wouldn't say I had any real technical issues, it's just my app was still in its fledgling phases and I had to build and tweak several minimally functioning routes/views/methods to make sure I was on the right track, the prelude to my big issues really, and by this time I could tell that the massive amounts of complex logic that 'Fwitter' had required would be a burden later and wouldn't be a logical long term set up for what I was trying to accomplish. But the functionality was slowly coming together.
**Day 4:** Official start of project week, should be done in 2 more days right? Nope. This is where the issues really started, as I went from a macro pov getting everything running to a micro pov in getting everythng presentable. Let's start with those damnable sessions. Disabling sessions didn't stop me from viewing the stories page, it instead just loaded the view for '/stories' on my '/login' page, causing me to have to resubmit every time i refreshed as if I was logging in. After playing with erb/redirect commands for 2 hours I finally discovered the issue was I couldnt progress much further without enabling sessions. We had a cohort wide issue where we had to enable session **at the top** of our ```configure``` method in our application folder, which was a really weird thing and seemingly the primary reason we had issues getting our sessions to set appropriately. Also I had a few rogue ```find``` methods that needed to be changed to ```find_by``` or ```find_by_id``` to help differntiate each User from one another.
**Day 5:** Ok so now that the sessions were working again, today was edit day! Once again, my 'Fwitter' based editing feature was overrun with logic that I had to cut down on to make it run more straightforward. Even moreso, I had to develop a 'post' route for my stories/:id which wasnt neccessary in the previous project, but Sinatra wouldnt let me advance wuthout it. Basically I had to learn to rewrite my neccessary methods in a totally differnet manner to get my program to function. And by the end of the day I had a funtioning edit feature with a dozen or so cluttered stories that I had nio way to delete.
**Day 6-7:** Ok, pressure's on, project week halfway through, but all I felt I needed was a delete feature to finish! Well, turns out my delete issue was tied into a deeper issue that would basically take me the remaining time to correct. After on;y being able to delete params and not remove from database, a few pry's showed me that there was A LOT of inconsistency with me ```.create``` method. I had changed it several times and my early stories werent saving anything, then stories weren't saving user_id, then I was good on everything, but modified it again somewhere and lost my user_id again (perhaps when I changed to my laptop and lost some progress for not pushing to github before switching machines). Needless to say how pain in the ass it was to try and save, edit delete with ```nil``` as the user_id, but the bigger problem was in my views. Because no user was assigned a user_id, I couldn't edit or delete several stories, and they were all available to view by any user, bust also disrupted my ability to set logical barriers to prevent user's from being able to delete/edit other user's projects (since at this point permissions haven;t been a subject for us). There were no fancy fixes here, the big issue was learning how to apply my ```current_user``` helper method and meticulously going through a dozen or so pages of code, making sure my tables were correct, relationships, grammatical/syntax errors etc. Then after that it was a simple matter of adding extremely minor logic to my views to block user's from viewing stories that didn't match the ```current_user.id``` with the ```@story.user_id```. But at 2am in the morning, after going thorugh all that I can proudly say it was all worth it. Then I remembered I had to write this damnable blog and recount all my work to the best of my ability.