【发布时间】:2016-09-12 21:48:28
【问题描述】:
我正在尝试使用辅助方法来确定多个记录的属性值。这是我试图开始工作的基本功能(从视图中):
<% if Baseline.where(subject_id: sub.subject_id).first.crf_status(crf) == 1 %>
<td bgcolor="#98FB98" >
<% else %>
我的辅助函数是crf_status(crf),它看起来像这样:
application_helper.rb
def crf_status(crf)
case crf
when Baseline then 'baseline_status'
when FollowUp3Week then 'follow_up_3_week'
...
end
end
因此,如果 crf_status(Baseline) 会返回:
<% if Baseline.where(subject_id: sub.subject_id).first.baseline_status == 1 %>
<td bgcolor="#98FB98" >
<% else %>
现在,错误是“基线的未定义方法 'crf_status'”。所以根据我读过的内容,也许我必须在每个控制器中引用 ApplicationHelper ?这听起来不对。请让我知道你的想法。
谢谢。
编辑。我忘了说清楚一点:crf_status(crf) 正在从数组 [Baseline, FollowUp3Week...] 中传递一个对象。
实际的行也以它开头 -> if crf.where(subject_id:...
【问题讨论】:
标签: ruby-on-rails ruby helpers