且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

表单中的第一个参数不能包含 nil 或为空 - Rails 4

更新时间:2022-06-14 06:23:28

错误消息告诉您不能有以下内容:

The error message is telling you that you can't have the following:

<%= form_for nil do |f| %>
<%= form_for [] do |f| %>

我的猜测是您的 @contact 设置为 nil 并且它不是来自您的 Contact#new 操作.

My guess here is that your @contact is set to nil and that it doesn't come from your Contact#new action.

仅供参考,如果您这样做,它会很简单:

FYI it would simply work if you do this:

<%= form_for Contact.new do |f| %>

虽然不推荐.

您需要检查包含您的表单的视图实际上是由您的 ContactsControllernew 操作呈现的.

You need to check that the view containing your form is actually rendered by the new action of your ContactsController.