【发布时间】:2016-11-25 19:51:30
【问题描述】:
我在尝试在我的索引视图中使用辅助方法时陷入困境。
在我的索引中,我有这样的观点:
<% policy_scope(Article).sort_by(&:created_at).in_groups_of(2) do |group| %>
<% group.compact.each do |article| %>
<h4><%= link_to article.title, article %></h4>
<small><%= state_notice(article) %></small><br>
<small><%= truncate(article.body, :ommission => "...", :length => 250) %></small>
<%= link_to 'READ MORE', article_path(article), :class=>"portfolio-item-view" %>
即:
在我的文章助手中有一个助手方法为:
module ArticlesHelper
def state_notice(article)
if current_user = article.user
article.text_for_state(current_state)
elsif article.to_be_reviewed and current_user.has_role?(:org_approver)
article.text_for_state(current_state)
else
'test'
end
end
def text_for_state(current_state)
case current_state
when 'draft'
'Private draft'
when 'review'
'Under pre-publication review'
when 'reject'
'This article has not been approved for publication'
when 'approve'
'This article has been approved for publication'
when 'publish'
'Published'
when 'remove'
'Removed from publication'
end
end
end
“to_be_reviewed”方法在我的文章政策中定义(我使用权威人士)。
我希望索引视图评估用户是否应该获取帮助程序中列出的 3 种情况之一的文本。相反,我收到一条错误消息:
undefined local variable or method `current_state' for #<#<Class:0x007fba81f217a8>:0x007fba8651f390>
Did you mean? current_user
.
谁能看出我哪里出错了?
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4 helper