0
我試圖找出如何從一個視圖訪問一個輔助方法,在相關的支架軌道4 - 如何使用幫助文檔中的相關部分
我有型號名爲Project和倫理。該協會是:
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
然後在我的項目文件夾查看,我有一個叫做偏其中_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>
任何人都可以看到我已經錯了嗎?
謝謝@Khanh - 這工作顯示助手的內容,但它顯示[「」]內的文字。我無法從助手中刪除這些標籤,因爲在顯示錶單時出現錯誤。 – Mel
因爲你把你的文本放在'數組'中,所以如果你想顯示文字爲'研究的解釋,參與者在研究中的角色的解釋',你只能寫成: 'text_for_subcategory(@category).join(「 「)' –
數組中只有一件事。數組的內容在表單中正確顯示,但在部分顯示中,它顯示在[「」]內。我只想顯示數組中選定元素的內容(在這種情況下,這是數組中唯一的內容。我不想顯示[「」] – Mel