我创建了一个辅助方法来动态更改表格中某些行的背景颜色:我的 html 如下所示:
<% @treatments.each do |f| %>
<tr class="<%= category_table_row_class(f.category) %>">
.....
还有我的辅助方法:
module ApplicationHelper
def category_table_row_class(category)
{ 0 => "success", 1 => "warning", 2 => "error", 3 => "info" }[category.id]
end
end
但是我有一些问题,我得到了错误:
Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id
我希望有人能帮助我吗?谢谢