I receive this error with my contact form in rails:
First argument in form cannot contain nil or be empty
View:
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>