我收到此错误我创建的页面模型和页面控制器我创建了一个联系人,谢谢你和_form页面。但我收到错误“页面中的NoMethodError #contact”
`显示/home/rohit/Desktop/inertiiaproject/inertiiatwo/app/views/pages/_form.html.erb第1行引发:
未定义的方法model_name' for NilClass:Class
pages_controller.rb文件
class PagesController < ApplicationController
def new
@pages = pages.new
end
def create
@pages = pages.new(params[:pages])
if @pages.deliver
render :thank_you
else
render :new
end
end
end
contact.html.erb
<h1>Want to get in touch?</h1>
<p>Please fill out the form below and we'll get back to you as soon as possible.</p>
<%= render 'form', :pages => @pages %>
_form.html.erb
<%= form_for pages do |f| %>
<% if pages.errors.any? %>
<ul>
<% pages.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
<% end %>
<div style="display: none;">
<%= f.label :nickname %><br/>
<%= f.text_field :nickname %>
</div>
<div>
<%= f.label :name %><br/>
<%= f.text_field :name %>
</div>
<div>
<%= f.label :email %><br/>
<%= f.text_field :email %>
</div>
<div>
<%= f.label :message %><br/>
<%= f.text_area :message %>
</div>
<div>
<%= f.submit "Send" %>
</div>
<% end %>