[Ruby] Active Record and Array error
Neil Moomey
neil at motznik.com
Thu Jun 21 11:55:51 PDT 2007
Hi everyone. I'm stumped on this seemly simple task. Below is my Model and
the error message. If Owner3 exists (from the db table anchorage_prop)
everything works fine but if Owner3 is null I get this error. There is
something special about the last member of this array. If I add something
else to the end of the array it works fine again. It's almost as if my
@anchorage_prop.owners.each do |q| wants to loop one more time than it
should. Any ideas? Thanks. - Neil
# Model AnchorageProp
class AnchorageProp < ActiveRecord::Base
set_table_name "anchorage_prop"
def owners
owner_array=[]
owner_array << "Owner1="+self.Owner1 unless self.Owner1.nil? ||
self.Owner1.strip == ""
owner_array << "Owner2="+self.Owner2 unless self.Owner2.nil? ||
self.Owner2.strip == ""
owner_array << "Owner3="+self.Owner3 unless self.Owner3.nil? ||
self.Owner3.strip == ""
end
________Browser Displays_________
NoMethodError in Anchorage_prop#details
Showing app/views/anchorage_prop/details.rhtml where line #60 raised:
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occured while evaluating nil.each
Extracted source (around line #60):
57: <td width="50%">
58: <span class="header1">OWNERS</span><br>
59: <span class="data1">
60: <% @anchorage_prop.owners.each do |q| %>
61: <%= h(q)%></br>
62: <% end %>
63: </span>
More information about the Ruby
mailing list