mercredi 8 avril 2015

How to render different versions of the same file?

For example I have this file:


_goal.html.erb



<table>
<tr>
<%= goal.name %>
<span class="label label-info"><%= goal.deadline.strftime("%d %b %Y") %></span>
</tr>
</table>


It is being rendered from the home page:



<h1><b>Goals</b></h1>
<%= render @unaccomplished_goals %>
<%= render @accomplished_goals %>
<% end %>


How can we wrap an accomplished goal with <span class="label label-info-success"> but if it is an unaccomplished goal keep it <span class="label label-info">?


In the controller:



@accomplished_goals = current_user.goals.accomplished
@unaccomplished_goals = current_user.goals.unaccomplished


Here was my latest attempt, which just made them all -info:



<% if @unaccomplished_goals == true %>
<span class="label label-info"><%= goal.deadline.strftime("%d %b %Y") %></span>
<% else @accomplished_goals == true %>
<span class="label label-warning"><%= goal.deadline.strftime("%d %b %Y") %></span>
<% end %>


Maybe you'll have more luck :)


Thank you so much.


Aucun commentaire:

Enregistrer un commentaire