Rails从添加到新视图的新操作发送实例变量

时间:2017-12-04 19:32:04

标签: ruby-on-rails ruby ruby-on-rails-5

这是我的路线:

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>

我该如何解决这个问题?感谢

0 个答案:

没有答案