문제

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
도움이 되었습니까?

해결책

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)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top