Reputation: 317
This is my code. I have a problem with spaces. I can not get the proper generation
- if @lastday.nil? && @lastday != item.created_at.strftime("%d %b %Y")
.daily-entry
%h1.date
=h item.created_at.strftime("%d")
%span
=h item.created_at.strftime("%b, %Y")
-else
.entry
%h1
= link_to item.title, "/items/#{item.id}"
Generates this is
<div class='daily-entry'>
<h1 class='date'>
20
<span>
Sep, 2009
</span>
</h1>
</div>
<div class='entry'>
<h1>
<a href="/items/15">xcvxcvx</a>
</h1>
</div>
But I want a HTML
<div class='daily-entry'>
<h1 class='date'>
20
<span>
Sep, 2009
</span>
</h1>
<div class='entry'>
<h1>
<a href="/items/15">xcvxcvx</a>
</h1>
</div>
</div>
.daily-entry
should be included in the condition
if condition true
<div class='daily-entry'>
<h1 class='date'>
20
<span>
Sep, 2009
</span>
</h1>
<div class='entry'>
<h1>
<a href="/items/15">xcvxcvx</a>
</h1>
</div>
</div>
if condition false
<div class='entry'>
<h1>
<a href="/items/15">xcvxcvx</a>
</h1>
</div>
Upvotes: 1
Views: 1567
Reputation: 52316
Looks like you'll have to duplicate the entry as a first cut:
-if @lastday.nil? && @lastday != item.created_at.strftime("%d %b %Y")
.daily-entry
%h1.date
=item.created_at.strftime("%d")
%span= item.created_at.strftime("%b, %Y")
.entry
%h1= link_to item.title, "/items/#{item.id}"
-else
.entry
%h1= link_to item.title, "/items/#{item.id}"
There ought to be a way to get aound that duplication, but I can't think what it should be - a helper function that takes a block, probably.
Upvotes: 1
Reputation: 146053
Don't you want
if [email protected]?
instead of
if @lastday.nil?
Upvotes: 2
Reputation: 5964
Just move the if
within the .daily-entry
:
.daily-entry
- if @lastday.nil? && @lastday != item.created_at.strftime("%d %b %Y")
%h1.date
=h item.created_at.strftime("%d")
%span
=h item.created_at.strftime("%b, %Y")
-else
.entry
%h1
= link_to item.title, "/items/#{item.id}"
Upvotes: 2