Topic: NoMethodError Get 500 instead of 200

Hi,  I've been going thru AGWD but Chapt 6 produced strange results:

First browser call to /Admin shows correct form; - And WEBrick reports:

"Get /admin HTTP/1.1" 200 485  - -> /admin

Subsequent browser calls to /Admin show: 
NoMethodError in AdminController#index
undefined method `each' for #<Mysql:0x37aba80>

- And WEBrick reports:

"Get /admin HTTP/1.1" 500 10767  - -> /admin


First browser call to /Admin/new shows correct form for editing; - And WEBrick reports:

"Get /admin/new HTTP/1.1" 200 10767   - -> /admin/new

Subsequent browswer calls to /Admin/new show:
NoMethodError in AdminController#new
undefined method `each' for #<Mysql:0x376d7e8>
RAILS_ROOT: ./script/../config/..

- And WEBrick reports:

"Get /admin/new HTTP/1.1" 500 9798  - -> /admin/new

So the first calls produce a "Get...200..." and the right browser results.
Subsequent calls produce a "Get...500..." and "NoMethodError"

Thanks for your help,

Re: NoMethodError Get 500 instead of 200

Could you post the code for AdminController index and new actions for us? The problem probably isn't with the code, I just want to make sure.

Railscasts - Free Ruby on Rails Screencasts

Re: NoMethodError Get 500 instead of 200

Maybe you've made changes in your routes.rb in the config folder?
Maybe try setting

map.connect 'admin/new', :controller => 'admin', :action => 'new'

in this file and see what happens. Can't see why this should be happening. On the other hand, your database may not be configured correctly.

Re: NoMethodError Get 500 instead of 200

Thanks for the quick response, My AdminController class:

def index 
list
render :action => 'list'
end

def new
@product = Product.new
end

My routes.rb:
map.connect ':controller/service.wsdl', :action => 'wsdl'
map.connect ':controller/:action/:id'

Re: NoMethodError Get 500 instead of 200

Hello Again everyone,

Can anyone help explain what the first set of numbers in WEBrick "Get" calls refers to?

For example what is the 500 in the following: "Get /admin HTTP/1.1" 500 10767

Compared to the 200 in the following:         "Get /admin HTTP/1.1" 200 485

The only code I have running is the scaffold code that rails creates.

I'm guessing that WEBrick is referring to 2 different locations possibly from multiple installs.

Thanks for any input,

Joe Noobie

Re: NoMethodError Get 500 instead of 200

Zachary sent me the following insight:

Ok Those are HTTP status headers, sent by the server to the browser, letting the browser know what happened in the request.

2xx is generally success
3xx is generally provisional success
4xx is generally inaccessible
5xx is generally server failure

See this page: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html for more details.

Re: NoMethodError Get 500 instead of 200

Can you post the 'list' method from the controller and the list view?

Subsequent browser calls to /Admin show: 
NoMethodError in AdminController#index
undefined method `each' for #<Mysql:0x37aba80>

This is very odd.  Bascially this is happening in the view code, where it it tries to iterate through the results and print them in html.  But what it's saying is that it can't find the 'each' method, because the result is a Mysql object, not an Array.  This object should be instantiated in the 'list' method.

Last edited by thabenksta (2006-08-25 09:33:26)

Re: NoMethodError Get 500 instead of 200

All of the code is generated by Rails - The only thing I created was the database.  I haven't modified any of the Rails default framework.

Re: NoMethodError Get 500 instead of 200

Joe wrote:

All of the code is generated by Rails - The only thing I created was the database.  I haven't modified any of the Rails default framework.

So do you have an 'admins' table?  The scaffold generator assumes that there is a table for the object you're working with.  It's useless without a table.

10

Re: NoMethodError Get 500 instead of 200

Agile Web Dev w/ Rails Chapt 6 has you set up a "Products" table.
Ruby script/generate scaffold Product Admin
I thought Admin is the name of the controller

Re: NoMethodError Get 500 instead of 200

It looks like the code might be all as it should be.  You might want to check out somebody else having the same problem:
http://lists.rubyonrails.org/pipermail/ … 60571.html

The "undefined method `each' for #<Mysql:0x376d7e8>" error may be indicative of a messed up Rails installation.  See if it works without the mysql gem:
$ gem remove mysql
or, if you don't have this gem maybe try installing it.
$ gem install mysql
if all else fails I recommend installing an earlier version on Rails and some of it's gems (Rails 1.0 should work fine).  Feel free to ask how to do that.

Last edited by danger (2006-08-25 21:33:58)