December 15, 2013 · ada

My Ada Developers Academy Blog: Week 7

So this week I learned about two cool rails functions: rendering partials and polymorphic paths.

I first figured out partials as we were working on reviews for our products on our amazon/etsy ripoff app. We had been shown the week before the way to render a yield of a view after using the layout erb files so I figured there must be a similar means to render an erb from another view.

I didn't know the name for what I wanted to do, so I had to spend some time googling. At first I thought it might also have a "yield" type wording, but that didn't return any clear results so I defaulted to my trusty old-fashioned method of typing out what I wanted to do the same way I would explain it to someone else and it ended up being a search along the lines of "how do i render part of an erb in rails". That did the trick! It led me to a stackoverflow question (of course), which gave me the word partial. Sadly it took me a long time to actually implement what I wanted because the internet seemed to presume that I already had somehow, through magic, figured out that a partial view always starts with an underscore in the file name. So after comparing my files with the default partial that I saw in our prior app (which we made with scaffolding), I was able to infer that the only difference I had was the file name. It was a quick fix, even though it was pretty frustrating at first. I feel like this is a pretty common experience for me, since even the beginner ruby guides on rubyonrails.org seem to be written under the assumption that the reader already has a basic knowledge of the vocabulary.

The other cool thing I learned about was polymorphic paths. This one I came across again from the depths of stackoverflow. I was trying to figure out how to get my reviews to be accessed from the products as well as from the users urls. I ended up in an hour+ long rabbit hole of information on rails on how to do this. Sadly most of it was really complicated and there were no good beginners guides so I sort of poked around trying to figure it out and learned a lot about how they are constructed. Of course, I wasn't able to get anything working since it was overly complicated for my skill level right now. In the morning the next day, I asked Bookis about it and he gave me a hilarious look of "the hell are you trying to do?!" before he figured out that I had just gotten sidetracked and what I really wanted was a nested resource. I was sort of disappointed by that solution, since I had learned about this cool new thing, but I am sure we will eventually build up to those skills and I will be able to figure it out later.

Comments on My Ada Developers Academy Blog: Week 7