我试图弄清楚如何从关联的脚手架中的视图中访问助手方法
我有一个叫做项目和伦理的模型。这些协会是:
Project has_many :ethics
Ethic belongs_to :project在我的道德助手中,我有:
module EthicsHelper
def text_for_subcategory(category)
if category == 'Risk of harm'
[ "Physical Harm", "Psychological distress or discomfort", "Social disadvantage", "Harm to participants", "Financial status", "Privacy"]
elsif category == 'Informed consent'
["Explanation of research", "Explanation of participant's role in research"]
elsif category == 'Anonymity and Confidentiality'
["Remove identifiers", "Use proxies", "Disclosure for limited purposes"]
elsif category == 'Deceptive practices'
["Feasibility"]
else category == 'Right to withdraw'
["Right to withdraw from participation in the project"]
end
end
end然后,在我的projects视图文件夹中,我有一个名为_ethics.html.erb的部分,它包含:
<% @project.ethics.each do | project_ethics_issue | %>
<strong>ETHICS CONSIDERATION: <%= project_ethics_issue.text_for_subcategory(@category) %></strong>
<%= project_ethics_issue.considerations %>
<% end %> 在我的项目控制器中,我尝试过:
include EthicsHelper当我尝试这样做时,我会发现一个错误:
undefined method `text_for_subcategory' for #<Ethic:0x007fedc57b7b58>有人能看到我哪里出了问题吗?
发布于 2016-06-20 02:02:02
在_ethics.html.erb文件中,您只将此代码修改为:
<% @project.ethics.each do | project_ethics_issue | %>
<strong>ETHICS CONSIDERATION: <%= text_for_subcategory(@category).join(",") %></strong>
<%= project_ethics_issue.considerations %>
<% end %> 更新:
我在您的文件ethics_helper.rb中看到,您的逻辑代码似乎不正确。
module EthicsHelper
def text_for_subcategory(category)
if category == 'Risk of harm'
[ "Physical Harm", "Psychological distress or discomfort", "Social disadvantage", "Harm to participants", "Financial status", "Privacy"]
elsif category == 'Informed consent'
["Explanation of research", "Explanation of participant's role in research"]
elsif category == 'Anonymity and Confidentiality'
["Remove identifiers", "Use proxies", "Disclosure for limited purposes"]
elsif category == 'Deceptive practices'
["Feasibility"]
elsif category == 'Right to withdraw'
["Right to withdraw from participation in the project"]
else
[]
end
end
endhttps://stackoverflow.com/questions/37913593
复制相似问题