更新时间:2023-11-30 22:07:58
您使用if inv
-如果不存在带有匹配电子邮件的邀请,由于inv
是ActiveRecord查询对象,它仍将返回true
.但是each
然后什么也不做,即没有重定向或显式呈现.默认渲染将被调用,并期望模板存在.
You use if inv
- this will still return true
if no invitations with matching email exist, since inv
is an ActiveRecord query object. But then the each
does nothing, i.e. does not redirect or render explicitly. Default render will be invoked and expect a template to exist.
使用if inv.present?
将解决此问题.
(此外,您可能要确保inv
集合仅包含一个结果.在同一请求中多次重定向或渲染将导致错误.)
(Also, you might want to make sure the inv
collection only contains one result. Redirecting or rendering multiple times in the same request will result in an error.)