我正在尝试显示按月份划分的客户的工作表。部分视图评估并使用binding.pry
每个我可以看到正确的值存在。 _month_section.html.erb
日期未显示,_jobs.html.erb
clients_controller.rb
def show
if id = params[:id]
if @client = current_user.clients.find_by_id(id.to_i)
if @client.jobs.count > 0
@jobs_by_month = @client.jobs.group_by{|j| j.created_at.strftime('%B %Y')}
end
else
redirect_to dashboard_path
end
end
end
show.html.erb
<% if @client.jobs.count > 0 %>
<div class="row">
<div class="col-lg-12 col-md-12">
<div class="panel panel-white">
<div class="panel-heading">
<h4 class="panel-title">Jobs</h4>
<div class="panel-body">
<%= render 'month_section' %>
</div>
</div>
</div>
</div>
</div>
<% end -%>
_month_section.html.erb
<div class="month_section" >
<% @jobs_by_month.each do |date, jobs| %>
<div>
<h3><%= date %></h3>
<%= render partial: 'jobs', :locals => {:jobs => jobs } %>
</div>
<% end %>
</div>
_jobs.html.erb
<div class="jobs">
<div class="row">
<div class="col-lg-12">
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>Date</th>
<th>Start Time</th>
<th>End Time</th>
</tr>
</thead>
<tbody>
<% jobs.each do |job| %>
<tr>
<td><%= job.date%></td>
<td><%= job.start_time %></td>
<td><%= job.end_time %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
</div>
</div>
答案 0 :(得分:0)
结果问题是由于我发布的代码段之外的show.html.erb
上有一个流氓未终止的div标签。