NoMethodError when attempting to display index

Ruby Nuby alert. This is a pretty basic question, probably.

I'm tinkering around with putting a Rails app on top of legacy database tables. Assume that the tables and their structures can not change. The database type is Oracle, but I don't think that database connectivity is a problem, because I can view an individual object via Rails. Going to http://127.0.0.1:3005/advisories/ZZ yields the following:

Advisory: ZZ

Descr: MISCELLANEOUS ADVISORY

Sort order: 0

Exclusivity: 0

Edit | Back

Okay, great, so, that's all well and good. However, when I click "Back" or get rid of the "/ZZ" on the URL, I get the following error:

NoMethodError in Advisories#index Showing advisories/index.html.erb where line #11 raised:

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

Extracted source (around line #11):

8: <th>Exclusivity</th> 9: </tr> 10: 11: <% for advisory in @advisories %> 12: <tr> 13: <td><%=h advisory.advisory %></td> 14: <td><%=h advisory.descr %></td>

(truncated)

Kind of seems like there must be some sort of problem in the controller's index method, no? How come it has no problem getting one particular entry, but listing the entire table's contents doesn't work?

Here's the table structure (notice that since this is a legacy table, there is no "id" column):

VIEW advisory Name Null? Type ----------------------------------------- --------

By the way, I should mention that the controller I have hasn't been modified since I generated it with Ruby 2.0's scaffold. Also, here's my model:

class Advisory < ActiveRecord::Base   set_primary_key :advisory end

Ruby Nuby alert(truncated)

Kind of seems like there must be some sort of problem in the controller's index method, no? How come it has no problem getting one particular entry, but listing the entire table's contents doesn't
work?

by default those are different methods (index & show) If you suspect something is wrong with the index method, why not show
us what it is?

Fred

Frederick Cheung wrote:

Ruby Nuby alert(truncated)

Kind of seems like there must be some sort of problem in the controller's index method, no? How come it has no problem getting
one particular entry, but listing the entire table's contents doesn't work?

by default those are different methods (index & show) If you suspect something is wrong with the index method, why not show us what it is?

Fred

Well, like I said, it's just the basic controller as generated by the scaffold. So, that gives us:

Well the view is using @advisories but the controller is using
@advisory which obviously isn't going to work

Fred

Frederick Cheung wrote: