我正在开发一个非常简单的新闻稿应用程序,但对此错误感到困惑。为什么要nil
上课?我只要求它渲染,所以为什么不能redirect_to
在render
调用位置放一个?
<% if admin_signed_in? %>
<p id="notice"><%= notice %></p>
<h1>Subscribedusers</h1>
<table>
<thead>
<tr>
<th>Email</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @subscribedusers.each do |subscribeduser| %>
<tr>
<td><%= subscribeduser.email %></td>
<td><%= link_to 'Show', subscribeduser %></td>
<td><%= link_to 'Edit', edit_subscribeduser_path(subscribeduser) %></td>
<td><%= link_to 'Destroy', subscribeduser, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to 'New Subscribeduser', new_subscribeduser_path %>
<% else %>
<%= render '/' %>
<% end %>
为什么这部分代码会<%= render '/' %>
触发undefined method 'empty?' for nil:NilClass
错误?
由于您希望将用户返回首页,而不是
render '/'
你应该用
redirect_to root_path
区别在于render
准备将输出显示为当前请求的结果,并redirect_to
命令用户的浏览器在指定的url处发出新请求。
尽管可以通过任意操作呈现主页的内容,但这很少是可取的。缺点之一是页面URL不会自动更新到浏览器地址栏中的站点根目录。
附带说明,render '/'
这不是正确的语法。render
通常接受选项的散列而不是字符串。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句