views:

33

answers:

1

I have a repeated line which outputs something like: Call John Jones in -3 days (status)

I have a helper called show_status(contact,email) which will output whether that particular email had been sent to that particular contact.

If it is "sent," then that entire line should show up as "strike out."

Similarly, if the number of days is -3 (<0), the line should be formatted in red.

Here's my hack, but there must be a cleaner way to put the logic into the controller?

I hard-code a value that wraps around the lines I want formatted, and assign the value based on a separate call to the same helper:

<% for call in @campaign.calls %>
        <% if !show_call_status(@contact,call).blank? %>
           <%= strike_start = '<s>'%>
           <%= strike_end = '</s>' %>
        <% end %>
        <p>
            <%= strike_start %>
            <%= link_to call.title, call_path(call) %> on 
        <%= (@contact.date_entered + call.days).to_s(:long) %> in <%= interval_email(@contact,call) %> 
        days 
        <%= make_call(@contact,call) %>
        <span class='status'><%= show_call_status(@contact,call) %></span>  
        <%= strike_end %>   
        </p>
<% end %>

I guess what I'd like to do is not have the if statement in the View. Not sure how to do this.

A: 

Basically, I would put a class on the p tag based on the status and have the CSS decide what needed to be done.

So the view:

<% for call in @campaign.calls %>
  <p class="<%= call_status_class(@contact, call) %>">
    <%= link_to call.title, call_path(call) %> on 
    <%= (@contact.date_entered + call.days).to_s(:long) %> in <%= interval_email(@contact,call) %> 
    days 
    <%= make_call(@contact,call) %>
    <span class='status'><%= show_call_status(@contact,call) %></span>  
  </p>
<% end %>

And another helper:

def call_status_class(contact, call)
  # do what you have to do to figure out status
  if overdue
    return 'overdue'
  elsif called
    return 'called'
  else
    return 'standard'
  end
end

Then in CSS:

.standard {
  ...
}
.overdue {
  color: red;
}
.called {
  text-decoration: line-through;
}

Pick and choose. I can't really give you full fledged solution without seeing all the helper functions. Hope this helps.

Tony Fontenot