w4d4 - Band Aid

♫ Help! I need sombody!
♫ Help! Not just anybody!
♫ Help! I need some help with Raiilllllsssss

    Actually, today was pretty fun! We had a solo day, and we were tasked with building an app that would serve as a sort of music catalog. We started with dealing with user sign up and authentication. After our work yesterday, this wasn’t too bad. It will definitely take some practice before it becomes second nature, but I felt like I knew what I was doing the whole time, and I generally had a good idea of what steps I needed to take in order to get the results I wanted.

    Once authentication was out of the way, it was time to add the meat of the app, which revolved around having resources for Bands, Albums and Tracks. Obviously they all needed to be associated properly, or the whole concept sort of falls apart. For the most part, I didn’t have much trouble setting things up, but with Rails, there are so many little areas where you can get tripped up, that things are always tricky. I plugged away slowly and steadily, trying to avoid making any major mistakes, and it worked well for the most part. I was able to get that part done by the end of class.

    It was great seeing how everything fit together nicely, and the flow of the application was pretty slick, even though it looked like crap! The main page displayed a list of all bands in the database, with links to each bands detail page. I even added a text field next to the band link with a count of how many Albums they had. From the index, you could add new bands to the database by following the ‘new_bands_url’ link. On the band detail page, you could see all of the Albums for that Band, and any Tracks for those Albums nested underneath. All of these were also links that took you to their detail pages. You could also click a link to submit a new Album. On that screen, you had the ability to select any Band to add the album to, but the default value was the Band whose page you were just on. The Album detail page was similar, it had links to all of it’s Tracks, and a link to add a new Track. Again, the new Track page defaulted to the Album you clicked from. Finally, there was the Track Detail page, which showed the name of the Band, the name of the Album, and listed out lyrics to the song (entered by users). There was a link to edit the track, where you could actually enter the lyrics.

    After class, most people stayed longer and tried to finish up. In this time, I was able to complete the next phase of the project, which was giving users the ability to add Notes to Track pages. Even better, they had the ability to delete notes, but only ones that they posted. Any actions they didn’t have access to were not visible, and in case they tried anything sneaky, they were also prevented by the Controller itself, which automatically redirected any users without access to make the change.

    The last piece, I actually added from home, which was adding in the formatting of “ugly lyrics”, as per our instructions. It wasn’t too bad, but it was good practice for figuring out which pieces of code you need to escape (to avoid code injection attacks), and which pieces you need to make “html_safe”, so that your page actually understands that it should be using it as valid html. To do this, I created a helper method that took the lyrics and split them into an array based on line breaks. For each line, I added a little note (♫) to the front and escaped out the actual text, pushing this into a new array. At the end, I just joined the new array together with new lines (“\n”), surrounded it in <pre> tags to preserves the formatting, and made the whole thing an html_safe string to generate my so called “ugly lyrics”. I think they look pretty awesome! But maybe that’s because it’s the ONLY graphical element of the app (if you could even call it that!). I’m definitely looking forward to the point where we can add a little bit of style, but that is still probably a few days away…