Skip to content

Commit

Permalink
DRY up events show page by extracting an _attendee_list partial
Browse files Browse the repository at this point in the history
Revert fancy usages of pluralize() helper to the three-argument form,
because the `pluralize(count, 'thing', plural: 'things')` form
is actually only available in Rails 5
  • Loading branch information
tjgrathwell committed May 29, 2016
1 parent 1574fff commit fa00cb5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 24 deletions.
4 changes: 2 additions & 2 deletions app/views/admin_pages/admin_dashboard.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@

<h2>Spammers</h2>
<div>
<%= pluralize(@spammers.count, "user has", plural: "users have") %> been flagged as a spammer.
<%= pluralize(@spammers.count, "user has", "users have") %> been flagged as a spammer.
<ul>
<% @spammers.each do |spammer| %>
<li><%= link_to spammer.full_name, user_profile_path(spammer) %></li>
Expand All @@ -101,7 +101,7 @@

<h2>Spam events</h2>
<div>
<%= pluralize(@spam_events.count, "event has", plural: "events have") %> been marked as spam.
<%= pluralize(@spam_events.count, "event has", "events have") %> been marked as spam.
<ul>
<% @spam_events.each do |event| %>
<li><%= link_to event.title, event %></li>
Expand Down
10 changes: 10 additions & 0 deletions app/views/events/_attendee_list.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<ul class="attendees">
<% attendees.each do |rsvp| %>
<li class='attendee'>
<%= user_gravatar(rsvp.loaded_user) %><%= link_to rsvp.loaded_user.full_name, rsvp.loaded_user.profile_path, class: rsvp_class(rsvp) %>
<% if rsvp.waitlist_position.present? %>
<span class='waitlist-number pull-right'>#<%= rsvp.waitlist_position %></span>
<% end %>
</li>
<% end %>
</ul>
29 changes: 7 additions & 22 deletions app/views/events/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,14 @@
<% end %>
</ul>
</div>

<h3><%= pluralize(@event.checked_in_rsvps(Role::VOLUNTEER).count, "volunteer") %>!</h3>
<% if @ordered_rsvps[Role::VOLUNTEER].none? %>
<div class="mb20">
No volunteers are currently signed up for this event.
</div>
<% else %>
<ul class="attendees">
<% @ordered_rsvps[Role::VOLUNTEER].each do |rsvp| %>
<li class='attendee'><%= user_gravatar(rsvp.loaded_user) %><%= link_to rsvp.loaded_user.full_name, rsvp.loaded_user.profile_path, class: rsvp_class(rsvp) %></li>
<% end %>
</ul>
<%= render 'attendee_list', attendees: @ordered_rsvps[Role::VOLUNTEER] %>
<% end %>
<% if @event.allow_student_rsvp? %>
Expand All @@ -140,30 +137,18 @@
No students are currently signed up for this event.
</div>
<% else %>
<ul class="attendees">
<% @ordered_rsvps[Role::STUDENT].each do |rsvp| %>
<li class='attendee'><%= user_gravatar(rsvp.loaded_user) %><%= link_to rsvp.loaded_user.full_name, rsvp.loaded_user.profile_path, class: rsvp_class(rsvp) %></li>
<% end %>
</ul>
<%= render 'attendee_list', attendees: @ordered_rsvps[Role::STUDENT] %>
<% end %>
<% end %>
<% if @ordered_waitlist_rsvps[Role::VOLUNTEER].any? %>
<h3><%= @ordered_waitlist_rsvps[Role::VOLUNTEER].length %> waitlisted <%= "volunteer".pluralize(@ordered_waitlist_rsvps[Role::VOLUNTEER]) %>!</h3>
<ul class="attendees">
<% @ordered_waitlist_rsvps[Role::VOLUNTEER].each do |rsvp| %>
<li class='attendee'><%= user_gravatar(rsvp.loaded_user) %><%= link_to rsvp.loaded_user.full_name, rsvp.loaded_user.profile_path %><span class='waitlist-number pull-right'>#<%= rsvp.waitlist_position %></span></li>
<% end %>
</ul>
<h3><%= pluralize(@ordered_waitlist_rsvps[Role::VOLUNTEER].length, "waitlisted volunteer") %>!</h3>
<%= render 'attendee_list', attendees: @ordered_waitlist_rsvps[Role::VOLUNTEER] %>
<% end %>
<% if @ordered_waitlist_rsvps[Role::STUDENT].any? %>
<h3><%= @ordered_waitlist_rsvps[Role::STUDENT].length %> waitlisted <%= "student".pluralize(@ordered_waitlist_rsvps[Role::STUDENT]) %>!</h3>
<ul class="attendees">
<% @ordered_waitlist_rsvps[Role::STUDENT].each do |rsvp| %>
<li class='attendee'><%= user_gravatar(rsvp.loaded_user) %><%= link_to rsvp.loaded_user.full_name, rsvp.loaded_user.profile_path %><span class='waitlist-number pull-right'>#<%= rsvp.waitlist_position %></span></li>
<% end %>
</ul>
<h3><%= pluralize(@ordered_waitlist_rsvps[Role::VOLUNTEER].length, "waitlisted student") %>!</h3>
<%= render 'attendee_list', attendees: @ordered_waitlist_rsvps[Role::STUDENT] %>
<% end %>
</div>
</div>

0 comments on commit fa00cb5

Please sign in to comment.