Ruby Question

How can I include ruby code to content_tag

I have content_tag with "td", where I must write codition on ruby. I wrote in the following way:

content_tag :td, class: "text-right<%= ' text-danger' if section.sum_control != (section.sum_self_summary + section.sum_sub_summary) %>", style: "width: 150px"

But it didn't work, how decide this problem?

Answer Source

May be you should do like this

cls = section.sum_control != (section.sum_self_summary + section.sum_sub_summary) ? 'text-right text-danger' : 'text-right'
content_tag(:td, class: cls, style: 'width: 150px')

Hope this is helpful

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download