# Missing model error

**URL:** <https://www.ruby-forum.com/t/missing-model-error/119199>\
**Category:** Rails\
**Created:** [November 4, 2007, 9:43pm UTC](https://www.ruby-forum.com/t/missing-model-error/119199 "2007-11-04T21:43:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [November 4, 2007, 9:43pm UTC](https://www.ruby-forum.com/t/missing-model-error/119199/1 "2007-11-04T21:43:57Z")

</div>

I am storing a shape object in a session, and somewhere I picked up  
that to make sure I can restore the full glory of Shape, I needed  
this line in ApplicationController

model :Shape

So, of course, I also have a file /app/models/shape.rb

All was working well, but then I decided I’d rather name the model  
MyShape.

So, I

- edited the filename to “my\_shape.rb”
- edited the shape.rb file to “class MyShape \< AR”
- edited “model :MyShape”

Now I get a “missing model error.”

Dude, it’s right there, I can see it.

However, I can’t find where I picked up that I needed to add the  
‘model’ line. So, I can’t remember all the details of why it’s there,  
what the rules are, what I am forgetting, etc.

Trying to figure out how to google for that one is a futile exercise.

Attempting to search various online docs for the Rails API are also  
fruitless.

Dazed, confused, and lost. And it was going so well for a while…

– gw

---

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [November 4, 2007, 9:48pm UTC](https://www.ruby-forum.com/t/missing-model-error/119199/2 "2007-11-04T21:48:02Z")

</div>

Did you restart the server?

-Bill

---

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [November 4, 2007, 9:48pm UTC](https://www.ruby-forum.com/t/missing-model-error/119199/3 "2007-11-04T21:48:37Z")

</div>

On 4 Nov 2007, at 20:42, Greg W. wrote:

> MyShape.
> 
> So, I
> 
> - edited the filename to “my\_shape.rb”
> - edited the shape.rb file to “class MyShape \< AR”
> - edited “model :MyShape”
> 
> Now I get a “missing model error.”
> 
> Dude, it’s right there, I can see it.

Have you tried clearing out your sessions. I’m guessing that it’s  
trying to restore your session, and since your session was created  
before you made the change it contains an instance of Shape, not  
MyShape.

> However, I can’t find where I picked up that I needed to add the  
> ‘model’ line. So, I can’t remember all the details of why it’s there,  
> what the rules are, what I am forgetting, etc.

I thought that was dead.

Fred

---

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [November 4, 2007, 9:55pm UTC](https://www.ruby-forum.com/t/missing-model-error/119199/4 "2007-11-04T21:55:39Z")

</div>

\*stale session. (what I get for doing 3 things at once)

-Bill

---

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [November 4, 2007, 9:52pm UTC](https://www.ruby-forum.com/t/missing-model-error/119199/5 "2007-11-04T21:52:44Z")

</div>

Ahh yes, I bet Fredrick is correct on the fact that it is trying to  
instantiate the incorrect class from a stale model and on the second  
point that it is no longer needed.

-Bill

---

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [November 4, 2007, 9:57pm UTC](https://www.ruby-forum.com/t/missing-model-error/119199/6 "2007-11-04T21:57:59Z")

</div>

> > - edited “model :MyShape”
> > 
> > Now I get a “missing model error.”
> 
> Have you tried clearing out your sessions.

Yes.

> Did you restart the server?

Yes.

In fact at this point, I’m trying both Shape and MyShape.

So I have all the original Shape code. And it works.

Then I have a new model (created by generate) called MyShape.

I add the line

model :MyShape

and even though I don’t actually use it anywhere yet, I get that  
error. You’d think all it has to do at that point is look for that  
file, yeah? Weird.

> > However, I can’t find where I picked up that I needed to add the  
> > ‘model’ line. So, I can’t remember all the details of why it’s there,  
> > what the rules are, what I am forgetting, etc.
> 
> I thought that was dead.

So I don’t even need to bother with this ‘model’ declaration? There’s  
no circumstances where it is needed (perhaps when not following some  
convention?)

– gw

---

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [November 4, 2007, 10:02pm UTC](https://www.ruby-forum.com/t/missing-model-error/119199/7 "2007-11-04T22:02:05Z")

</div>

On Nov 4, 2007, at 12:55 PM, William P. wrote:

> \*stale session. (what I get for doing 3 things at once)

Yeah, I figured. I appreciate that helping me was one of those  
things 🙂

So, anyway, I nuked the model line, changed my names as needed, and  
everything works fine. So, for now I’ll just forget this ever  
happened, and worry about model :x some other day when I need to.

Thanks guys.

– gw
