Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined method model_name

I'm using the default code created by scaffolding. I haven't changed anything.

Showing app/views/presences/_form.html.erb where line #1 raised: 
undefined method `model_name' for NilClass:Class

1: <%= form_for(@presence) do |f| %>
2:   <% if @presence.errors.any? %>
3:     <div id="error_explanation">
4:       <h2><%= pluralize(@presence.errors.count, "error") %> prohibited this presence from being saved:</h2>

What is wrong here? I'm never calling a method called "model_name" and this code is automated, so why doesn't it work?

Thanks

like image 993
Bv202 Avatar asked Jun 21 '11 18:06

Bv202


1 Answers

Try adding this to your presences_controller in the new or other relevant action that is rendering the form:

#presuming your model is called Presence
@presence = Presence.new 
like image 68
Zabba Avatar answered Nov 18 '22 10:11

Zabba