如何根据助手的输出更改某些动态文本的标签/css 类?

发布于 2024-08-31 16:14:18 字数 1038 浏览 2 评论 0原文

我有一个重复的行,输出如下: 在 -3 天后致电 John Jones(状态)

我有一个名为 show_status(contact,email) 的助手,它将输出该特定电子邮件是否已发送给该特定联系人。

如果它是“已发送”,那么整行应该显示为“删除线”。

同样,如果天数为 -3 (<0),则该行的格式应为红色。

这是我的技巧,但必须有一种更干净的方法将逻辑放入控制器中?

我硬编码了一个包含我想要格式化的行的值,并根据对同一助手的单独调用来分配该值:

<% 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 %>

我想我想做的不是 if视图中的声明。不知道该怎么做。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心房的律动 2024-09-07 16:14:18

基本上,我会根据状态在 p 标记上放置一个类,并让 CSS 决定需要做什么。

所以视图:

<% 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 %>

另一个助手:

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

然后在 CSS 中:

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

选择并选择。如果没有看到所有辅助函数,我无法真正为您提供完整的解决方案。希望这有帮助。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文