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

前端 未结 7 1734
刺人心
刺人心 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:27

    I had a similar problem where I had a form in a modal that made changes to a model that was different than what the background page was showing. Even though I had the required @contact = Contact.new in my Contact controller, I needed to add this code within the controller for the background page.

    For example, I have a PhoneBook model and within my index view for PhoneBook I have a modal with a form that adds a contact to my Contact model. I need @contact = Contact.new within my index method in my PhoneBook controller:

    class PhoneBook < ApplicationController
    
      def index
        @contact = Contact.new
        ...
      end
    end
    

    And then the form within my modal that is being shown on PhoneBook index.html has the same syntax as others have written:

    <div id="phoneBook">
      <div id="myModal" class="modal">
        <%= form_for @contact do |f| %>
        ...
      </div>
    </div>
    
    0 讨论(0)
提交回复
热议问题