First argument in form cannot contain nil or be empty - Rails 4

前端 未结 7 1743
刺人心
刺人心 2020-12-04 19:24

I receive this error with my contact form in rails:

First argument in form cannot contain nil or be empty

View:

7条回答
  •  旧巷少年郎
    2020-12-04 20:03

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

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

    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| %>
    

    Though it is not recommended.

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

提交回复
热议问题