Skip to content

Instantly share code, notes, and snippets.

@koriroys
Created March 26, 2012 04:32
Show Gist options
  • Save koriroys/2202946 to your computer and use it in GitHub Desktop.
Save koriroys/2202946 to your computer and use it in GitHub Desktop.
How to make an empty column still show up?
<div class="span12">
<div class="row">
<div class="span3">Not Yet Started
<% story.tasks.each do |task| %>
<%= render task if task.not_yet_started? %>
<% end %>
</div>
<div class="span3">In Progress
<% story.tasks.each do |task| %>
<%= render task if task.in_progress? %>
<% end %>
</div>
<div class="span3">In Review
<% story.tasks.each do |task| %>
<%= render task if task.in_review? %>
<% end %>
</div>
<div class="span3">Complete
<% story.tasks.each do |task| %>
<%= render task if task.complete? %>
<% end %>
</div>
</div>
</div>
</div>
<div class="row">
<div class="span12">
<h1>Story Title <%= link_to '+', new_task_path(:story_id => story.id) %> </h1>
<div class="row">
<% story.tasks.group_by(&:status).sort.each do |status, task| %>
<div class="span3"><%= status_column_text(status) %>
<p>(<%= status %>)</p>
<% task.each do |task| %>
<p><%= link_to task.title, task %></p>
<% end %>
</div>
<% end %>
</div>
</div>
<div class="row">
<% sorted_stories = Hash[story.tasks.group_by(&:status).sort] %>
<% (1..4).each do |status| %>
<div class="span3">
<%= status_column_text(status) %>
<% if sorted_stories[status].present? %>
<% sorted_stories[status].each do |task| %>
<p><%= task.title %></p>
<% end %>
<% end %>
</div>
<% end %>
</div>
@koriroys
Copy link
Author

Hey Trevor, I implemented it with group_by. Only problem is, blank columns just disappear, when I want those blank columns to still show up, just be empty. Is group_by really what I want? (It does look cleaner, that's for sure)

@trevorturk
Copy link

Maybe you could build the headers outside of the group_by each block?

@umtrey
Copy link

umtrey commented Mar 28, 2012

You should then take the results of that query, and right join it with a list of all statuses. That way all statuses are included, but the field with the results would be blank if there are none there.

@koriroys
Copy link
Author

@trey that's kinda what i did with works.rb, but more hacky. I'll leave that fun join stuff up to you, sir.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment