On Jul 21, 2012, at 8:52 PM, James Harris wrote:

> In the console doing contact = Contact.find(1) finds my contact and the 
> contact.company.company_name returned the correct company name.
> 
> Having contact.company.company_name in the index.html file returns an 
> error:
> 
> undefined method `company_name' for nil:NilClass

You can figure out why that is nil, or you can just guard around it:

contact.company.try(:company_name)

My guess is that this particular contact does not have a company associated 
with it.

Walter

> 
> -- 
> Posted via http://www.ruby-forum.com/.
> 
> -- 
> 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 https://groups.google.com/groups/opt_out.
> 
> 

-- 
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 https://groups.google.com/groups/opt_out.


Reply via email to