When a project is new, it’s easy to just access what you need, where you need it. This inline access however becomes complicated quickly. This can be mitigate by moving away from inline, adhoc access, and formalizing things into reusable pieces. There are gems like ViewComponent and Phlex, but Rails can do a lot of this natively too.
Over the next few emails, we’ll take this:
<% Post.offset(params.fetch(:page, 0) * 25).limit(25).each do |post| %>
<div>
<h2><%= post.title %></h2>
<%= post.body %>
</div>
<% end %>
and turn it into:
<%= render PostPage.new(params) %>
We’ll flesh out our starting position tomorrow.