Help with variables

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

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

Hi Ron,

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

Fred

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
that should call up the controller code, no?

Thanks,

Ron

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.

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.

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