我有一个简单的轨道应用程序,我试图写一个视图助手,执行以下操作。在视图助手中的条件CSS的轨道
比较两个值。如果current_month的金额大于预测金额,则将文本设为绿色。如果current_month的金额低于预测金额,则将文本设为红色。
我写出了这个简单的助手,以将文本追加到rails方法的输出,但我不确定如何注入CSS /样式到此。
def target_hit(forecast, current)
(if current.amount > forecast.amount
number_to_currency(current.amount.to_s) + " Yay"
elsif current.amount < forecast.amount
number_to_currency(current.amount.to_s) + " No dice"
end).html_safe
end
我非常精通后端,但当涉及到前端的东西,我绊倒了很多。任何帮助将不胜感激。
例如图码
<p class='total'>Current: <%= target_hit(@forecast, @current) %></p>
您还可以从一个类的辅助方法。或者在你的target_hit方法中,你可以使用content_tag来定义类。我需要看到你的观点来提供一个例子。 – margo
@margo我提供了关于我如何称此方法的观点摘录。 – nulltek