I don’t know why I thought Rails layouts and templates would be somewhat easy. While in a sense it’s taking snippets and putting them in other files to reuse of course there has to be some logic in there to ensure that the proper data is being shown. So rendering partials with locals is starting to make sense.
For my example <%= render partial: "authors/author", locals: {author: @author} %>
– The first key-value pair partial: "authors/author"
tells Rails the name of the partial to render. Nothing too complex here.
– In the second key-value pair locals: {author: @author}
the nested hash {author: @author}
key is the name of the variable and its value is the value you’d like it to have in the partial.
I pretty much understand this except for the nested hash’s key. It’ll click I’m sure. I need to get into the Rails console and play some. I have figured out that to effectively have a partial inside a loop I need the argument I pass to the block (the piece in between the |pipes|) the same as the nested hash value. In this case @author
.
I’m thinking about presenting a general overview of MVC to my Free Code Camp meetup this weekend. Since I’m basically not thinking about JS at all right now I want to contribute in a meaningful way somehow. Depending on how long that presentation is I might add REST to it. Both MVC & REST are language agnostic so it’ll be useful. Maybe even add CRUD for a 30,000 feet overview of some of the big acronyms in web development.
Time spent today: 2:12
Time spent total: 244:26
Lessons completed today: 4
Lessons completed total: 470