Skip to content

Instantly share code, notes, and snippets.

@johana-star
Last active August 29, 2015 14:02
Show Gist options
  • Save johana-star/bde0b21c2f1db0e14038 to your computer and use it in GitHub Desktop.
Save johana-star/bde0b21c2f1db0e14038 to your computer and use it in GitHub Desktop.
Showing partials with locals in Sinatra
<%# BEFORE %>
<%# views/twiends_index.erb %>
<div class="twiends">
<%= @twiends.count %>
<table>
<tbody>
<% @twiends.each do |friend| %>
<tr class="<%= ("location-enabled" if friend[:geo_enabled]) %>">
<td>
<img src="<%= friend[:profile_image_url] %>"/>
</td>
<td>
<%= friend[:name] %>
</td>
<td>
<% link = "http://twitter.com/#{friend[:screen_name]}" %>
<a href="<%= link %>"><
<%= friend[:screen_name] %>
</a>
</td>
<td>
<%= friend[:location] %>
</td>
<td>
<%= friend[:followers_count].to_f / friend[:friends_count] %>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
<%# AFTER %>
<%# views/twiends_index.erb with a partial %>
<div class="twiends">
<%= @twiends.count %>
<table>
<tbody>
<% @twiends.each do |friend| %>
<%= erb :twiends_show, locals: { friend: friend } %>
<% end %>
</tbody>
</table>
</div>
<%# view/twiends_show.erb using the local passed by %>
<tr class="<%= ("location-enabled" if friend[:geo_enabled]) %>">
<td>
<img src="<%= friend[:profile_image_url] %>"/>
</td>
<td>
<%= friend[:name] %>
</td>
<td>
<% link = "http://twitter.com/#{friend[:screen_name]}" %>
<a href="<%= link %>"><
<%= friend[:screen_name] %>
</a>
</td>
<td>
<%= friend[:location] %>
</td>
<td>
<%= friend[:followers_count].to_f / friend[:friends_count] %>
</td>
</tr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment