On 18 August 2011 21:58, Dorijan Jelincic <dma...@gmail.com> wrote: > 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 :) 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.
<%= 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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.