这是我的路线:
get '/historico_cierres', to: 'cierres#historico_cierres'
这是我在控制器中的自定义方法
def historicos_cierres
fecha = DateTime.now.strftime "%Y/%m/%d"
@cierres_historicos = @negocio.cierres.where(fecha: fecha)
respond_to do |format|
format.html { redirect_to @cierres_historicos }
format.json { render :show, status: :created, location: @cierre }
end
这是我的观点/cierres/historico_cierres.html.erb
<tbody>
<% @cierres_historicos.each do |cierre| %>
<tr>....
<% end %>
这就是错误:
undefined method `each' for nil:NilClass
<tbody>
<% @cierres_historicos.each do |cierre| %> // IN THIS LINE
<tr>
我该如何解决这个问题?感谢