Created
March 26, 2012 04:32
-
-
Save koriroys/2202946 to your computer and use it in GitHub Desktop.
How to make an empty column still show up?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
Maybe you could build the headers outside of the group_by each block?
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.
@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
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)