erb 中的 partial 可选参数

Optional Parameters in View Partials
更新于: 2021-11-19 14:43:16
# _tags.html.erb
<% if tags.any? %>
  <div class="is-tags">
    <strong>标签: </strong>
    <% tags[0..(limit ||= 5)].each do |tag| %>
      <span class="badge bg-dark"><%= tag.name %></span>
    <% end %>
  </div>
<% end %>

# index.html.erb
<%= render partial: "shared/tags", locals: { tags: post.tags } %>