나는 내가 content_tag(:address) do....
를 사용하려고하면 Rails 3.1
content_tags를 사용하여이 엉망을 정리하는 방법은 무엇입니까?
def site_address(site)
html = '<address>'
html += site.address1 if site.address1.present?
html += tag(:br) + site.address2 if site.address2.present?
html += tag(:br) + site.city + ', ' if site.city.present?
html += site.state.statecode if site.state.present?
html += ' ' + site.zipcode if site.zipcode.present?
html += '</address>'
html.html_safe
end
에 content_tag
으로 정리하고 다음 블록에 내용을 넣을 수없는 것,이 도우미 메서드를 가지고, 그냥 내 <br />
태그를 이스케이프합니다.
표에는 Null 값이있을 수 있으므로 if.present?
논리가 많이 있음을주의하십시오.
감사합니다.
감사합니다. 나는 존재 방법에 대해서조차 몰랐다. – cbmeeks