# Help with variables

**URL:** <https://www.ruby-forum.com/t/help-with-variables/131582>\
**Category:** Rails\
**Created:** [March 11, 2008, 4:38pm UTC](https://www.ruby-forum.com/t/help-with-variables/131582 "2008-03-11T16:38:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecae2f/32.png) [@ron](https://www.ruby-forum.com/u/ron)\
**Post date:** [March 11, 2008, 4:38pm UTC](https://www.ruby-forum.com/t/help-with-variables/131582/1 "2008-03-11T16:38:44Z")

</div>

Okay, I know this is a really beginner question. But…

I created a migration to create an entity post. I gave it a title. I  
ran the migration.

Then, I created an admin controller, entitled simply admin\_controller.

I defined an index action like so:

def index  
@posts=Post.find(:all)  
end

Then I created an index view:

\<% @posts.each do |post| %\>  
\<%=post.title%\>  
\<%end%\>

What do I get?

You have a nil object when you didn’t expect it!  
You might have expected an instance of Array.  
The error occurred while evaluating nil.each

So I created a migration to add a row to the database so there would  
be at least one. Still get the nill object. What’s going on? What  
really basic thing have I overlooked?

Ron

---

<div class="post-metadata">

**Author:** ![ron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecae2f/32.png) [@ron](https://www.ruby-forum.com/u/ron)\
**Post date:** [March 11, 2008, 4:44pm UTC](https://www.ruby-forum.com/t/help-with-variables/131582/2 "2008-03-11T16:44:03Z")

</div>

On 11 Mar 2008, at 15:37, Ron wrote:

> def index
> 
> You have a nil object when you didn’t expect it!  
> You might have expected an instance of Array.  
> The error occurred while evaluating nil.each

Hi Ron,

That looks ok. Are you sure the code in your action is getting  
executed ?

Fred

---

<div class="post-metadata">

**Author:** ![ron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecae2f/32.png) [@ron](https://www.ruby-forum.com/u/ron)\
**Post date:** [March 11, 2008, 4:53pm UTC](https://www.ruby-forum.com/t/help-with-variables/131582/3 "2008-03-11T16:53:41Z")

</div>

Hi Fred,

Thanks for looking at it…I thought it looked okay. How would I find  
out if the code was being executed? I’m just using the default  
routing configuration, so if I type [http://localhost:3000/admin/index](http://localhost:3000/admin/index)  
that should call up the controller code, no?

Thanks,

Ron

On Mar 11, 8:43 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![ron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecae2f/32.png) [@ron](https://www.ruby-forum.com/u/ron)\
**Post date:** [March 11, 2008, 5:13pm UTC](https://www.ruby-forum.com/t/help-with-variables/131582/4 "2008-03-11T17:13:50Z")

</div>

Well, so I created a separate pages controller. It works from the  
pages controller.

localhost:3000/pages/

But it doesn’t work when I type

localhost:3000/admin/index

Now, when I type in admin, I get

undefined method `find’ for ActionController::Caching::Pages:Module

Both controllers have identical code.

---

<div class="post-metadata">

**Author:** ![ron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecae2f/32.png) [@ron](https://www.ruby-forum.com/u/ron)\
**Post date:** [March 11, 2008, 5:05pm UTC](https://www.ruby-forum.com/t/help-with-variables/131582/5 "2008-03-11T17:05:35Z")

</div>

Hmm…I just restarted my webbrick server and it worked. That’s  
strange. I thought you didn’t have to restart the server for new  
actions.

---

<div class="post-metadata">

**Author:** ![ron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecae2f/32.png) [@ron](https://www.ruby-forum.com/u/ron)\
**Post date:** [March 13, 2008, 10:21am UTC](https://www.ruby-forum.com/t/help-with-variables/131582/6 "2008-03-13T10:21:22Z")

</div>

On Mar 11, 4:12 pm, Ron [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Well, so I created a separate pages controller. It works from the  
> pages controller.
> 
> localhost:3000/pages/

pages might be a magic name (given that there is an actioncontroller  
module of the same name to do with page caching). By having a  
controller there you might be messing things up.

Fred
