How can I change the tags/css class of some dynamic text based on output from a helper?

Posted by Angela on Stack Overflow See other posts from Stack Overflow or by Angela
Published on 2010-05-03T21:06:55Z Indexed on 2010/05/03 22:58 UTC
Read the original article Hit count: 222

Filed under:
|

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.

© Stack Overflow or respective owner

Related posts about helper

Related posts about ruby-on-rails