August 20, 2015 Log No. 376

CatRecords =^v^=

For all your feline listening needs! Actually I should have done that instead of lamely choosing real bands and songs. Then I probably would have spent most of my day coming up with horribly punny and/or childish cat songs instead of trying to get a dynamically generated site navigation bar up, which was how my day was actually spent.

But it was super cool, for what it’s worth! It was our first solo day with Rails, and we were tasked with setting up a music website, replete with models, views, controllers, data, you name it. Since we weren’t supposed to be styling things yet really, I turned most of my attentions to exploring all the rails helper methods via routes, associations, etc, and it’s starting to get more intuitive. For example, we were supposed to have navigation between band <=> album <=> track, but I didn’t want to type out a lot of hardcoded links, so I spent time setting up a bar that had stuff like this:


<td>
<a href="<%= send("edit_" + section + "_url", params[:id]) %>">Edit <%= section %></a>
</td>
<td>
<a href="<%= send("delete_" + section + "_url", params[:id]) %>">Delete <%= section %><a>
</td>


<% if !path.include?("/tracks")
down_section = down_a_level(section) %>
<td>
<a href="<%= send(down_section + "_url") %>?<%= section %>_id=<%= params[:id] %>">See <%= down_section %></a>
</td>
<% end %>


<td>
<% if path.include?("/bands") %>
<a href="<%= send(up_section + "_url") %>">
<% else %>
<a href="<%= send(up_section + "_" + section + "_url") %>">
<% end %>
See <%= up_section %></a>
</td>

I mean, hardly the neatest, but it does crudely get the job done and work! So in any given section (band, album, track), it will use the correct noun and link to the correct links, as well as provide links up and down to the relevant album, track, band, what-have-you. Pretty sweet.


Leave a Reply

Your email address will not be published. Required fields are marked *

*