I have a form that I want to display at the top of each page, so I included it in the file /app/views/layouts/application.html.erb and I got the undefined methodmodule_name error for NilClass: Class` when trying to load the page.
Here is a form fragment in application.html.erb
<%= form_for @user do |f| %>
<h3>Add new contact</h3>
<%= f.text_field :first_name %><br />
<%= f.text_field :last_name %>
<%= f.text_field :email %>
<hr />
<%= f.submit "Add Contact" %>
<% end %>
Here is my / app / controllers / user _controller.rb
class UserController < ApplicationController
def index
end
def new
@user = User.new
end
end
I think I'm getting this error because, because the form is in the application.html.erb file, I need to somehow specify the path, but again I am very new to rails.
Let me know if you need anything else.
EDIT
Next Ola offer. In my app / views / layouts / application.html.erb file, I have something like this:
<div>
<%= yield :add_user %>
</div>
app/views/users/new.html.erb
<% content_for :add_user do %>
<%= form_for @user do |f| %>
<h3>Add new contact</h3>
First Name<br />
<%= f.text_field :first_name %><br />
Last Name<br />
<%= f.text_field :last_name %><br />
Email<br />
<%= f.text_field :email %>
<hr />
<%= f.submit "Add Contact" %>
<% end %>
<% end %>
, url http://localhost:3000/admin/index add_user content_for app/views/admin/index.html.erb