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
----------------------------------------- --------
----------------------------
ADVISORY VARCHAR2(4)
DESCR VARCHAR2(80)
SORT_ORDER NUMBER(3)
EXCLUSIVITY NUMBER(3)
Any ideas? Thanks very much in advance for your help!
--
Posted via http://www.ruby-forum.com/.
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
Well, like I said, it's just the basic controller as generated by the
scaffold. So, that gives us:
class AdvisoriesController < ApplicationController
# GET /advisory
# GET /advisory.xml
def index
@advisory = Advisory.find(:all)
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @advisory }
end
end
# GET /advisory/1
# GET /advisory/1.xml
def show
@advisory = Advisory.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @advisory }
end
end
(truncated)
>
> Frederick Cheung wrote:
>> On 13 May 2008, at 16:35, Gabe Heafitz 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
Ah ha. Well, there you go. I wasn't lying when I said "Ruby Nuby alert",
now, was I? :D I guess I just figured that Ruby's pluralizations and
inflections would take care of that. I guess I'll have to pay closer
attention to that in the future.
Thanks very much!