newbie: handling a method error

Hi...
I have 2 tables, connected with belongs_to and has_one and everything
works ok until I get one entry in base where I dont have set id of
belongs_to entry. How can I prevent it(except that that all entry has
ids :slight_smile: or dont print anithing in view?

this is what I am talking about:
I have customer and it has firm_id
trable firm has id and name

so when I try to print
customer.firm.name I got error.
Thank you

<%= customer.firm.name if customer.firm %>

Or possibly better to provide a method, say firm_name, of Customer
that tests self.firm and returns the name or nil or maybe a default
string if that is what you want, then do

<%= customer.firm_name %>

Colin

FWIW, I found Avdi Grimm's e-book on this topic well worth the price:

  <http://exceptionalruby.com/>

FWIW, I found Avdi Grimm's e-book on this topic well worth the price:

<http://exceptionalruby.com/>

thank you...I will look into to..
I resolve the issue like this:
in my controller, I asked if firm_id==nil, and if it is nil, I
assigned 0 value, witch is in my database described as "Not
selected"...