Question

The problem is, some Organization(s) don't have addresses and it breaks the page (Couldn't find OrganizationUrl with id=1826_). \

I'd like to somehow use the link if the address is present, and if not just show the name.

Any pointers?

@lot.organizations.collect{ |o| link_to(o.name, OrganizationUrl.find(o.org_id).address, :target => '_blank') }.to_sentence.html_safe
Was it helpful?

Solution

I ended up doing something like this (which is gross).

def link_to_many_organization(lot)
 @lot.organizations.map{ |o| 
  begin
    _url = OrganizationUrl.find_by_organization_id(o.org_id).address
  rescue
    o.name
  else
    link_to(o.name, _url, :target => '_blank')
  end
    }.to_sentence.html_safe
end  

and the usage:

= link_to_many_organization(@lot)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top