我以前问此相关的问题,但没有发现任何帮助Rails 4 - how to use a helper method in an index viewRails 4 - 如何在索引视图中使用辅助方法?
林其在这方面同样的问题。在我的索引操作中使用帮助器方法一定会阻止我。
我有一个索引视图和一个显示视图。帮手在展会视图中正常工作。
在我的索引视图我有:
<% @eois.sort_by(&:created_at).each do |eoi| %>
<div class="col-md-3 col-sm-5 portfolioitem Scienza">
<div class="portfolio-item text-center">
<h4><%= link_to eoi.user.full_name %></h4>
<span>Interested<%= display_interest(eoi) %></span>
<%= link_to 'VIEW DETAILS', project_eoi_path(@project, eoi), :class=> "portfolio-item-view" %>
</div>
</div>
<% end %>
在我的节目的看法,我有:
<td><%= @eoi.user.full_name %></td>
<td><%= @eoi.user.profile.organisation.try(:title) %></td>
<td>Interested<%= display_interest(@eoi) %></td>
<td><%= @eoi.created_at.try(:strftime, '%e %B %Y') %></td>
在帮助我的文件,我有:
def display_interest(eoi)
if interested_in_contributing
'in contributing resources to this project team'
elsif interested_in_participating
'in participating in this project'
elsif interested_in_partnering
'in partnering with this project team'
elsif interested_in_granting
'in assessing this project for a grant'
elsif interested_in_investing
# elsif eoi.invest || @invest
'in investing in the outcomes of this project'
else
nil
end
end
# Depending on the type of interest, then figure out which questions need to be asked.
# If the interest is in participation - there is no need to ask questions relating to asset requests
# TODO - need a better way to check the js on participant_intrest to feed through this same channel
def interested_in_participating
@eoi.participate || @participate
end
# If the interest is in contributing assets or partnering, need to check which assets are relevant to the interest
def interested_in_contributing
@eoi.contribute || @contribute
end
怎么来的我不能使用索引视图中的帮助文件?
控制器:
def index
@eois = Project.by_user_id(current_user.id).find_by(id: params[:project_id]).try(:eois) || Eoi.none
policy_scope(@eois)
end
def show
@eoi = Eoi.find(params[:id])
authorize @eoi
end
“必须有东西阻止我在我的索引操作中使用帮助器方法” - 多数民众赞成在奇怪什么是你得到的错误? –
未定义的方法'贡献'零:NilClass – Mel
你应该传递参数给你的帮手,而不是试图依靠实例变量。 –