0

시나리오/목적은 다음과 같습니다보기의 조건을 최상의 사용?

방문자가 홈페이지에있는 경우 헤드 탐색에있는 링크는 다음과 같습니다 "빌라", "아파트", "B & B" 방문자가 국가 페이지에있는 경우 (예 : en/italy) 머리 탐색의 링크는 다음과 같습니다. "Villas Italy", "Apartments Italy", "B & B 이탈리아" 방문자가 지역 페이지 (예 : en/italy/tuscany) 머리 탐색에서이 있습니다

: "빌라 토스카", "아파트 토스카", "B & B 투스카니은"

이 내 코드입니다

%ul.dropdown-menu.span3 
- if @country.present? 
    %li 
    %b 
    = link_to "#{t('navigation.nav.houses_all')} #{@country.name}", country_houses_path(@country) 
    %li.divider 
    %li.nav-header Thema's 
    - @country.tags.each do |a| 
    %li 
     #{link_to a.nav_content, tag_country_houses_path(a.country, a.name).capitalize} 
- if @region.present? && @country.present? 
    %li 
    %b 
    = link_to "#{t('navigation.nav.houses_all')} #{@region.name}", country_region_houses_path(@country, @region) 
    %li.divider 
    %li.nav-header Thema's 
    - @region.tags.find_each(:conditions => "active_house = true") do |a| 
    %li 
     #{link_to a.nav_content, tag_country_region_houses_path(@country, @region, a.name)} 
- else 
    %li 
    %b 
    = link_to "#{t('navigation.nav.houses_all')}", houses_path 
    %li.divider 

그래서 내가 원하는 것은 @ 영역 값이 설정되었을 때입니다. nav @country 값의 일부를 표시하고 싶습니다. 다른 부분을 표시하려고합니다. 그러나 내가 지역 페이지 (en/italy/tuscany)에있을 때 @country도 설정되기 때문에 @country nav 부분도 표시됩니다.

어떻게 해결할 수 있습니까? 당신이 원하는 것은 더 @region 메뉴가없는 경우에만 @country 메뉴를 표시하는 경우

답변

1

, 당신은 elsif으로 시도 할 수 있습니다 :

%ul.dropdown-menu.span3 
- if @region.present? && @country.present? 
    %li 
    %b 
    = link_to "#{t('navigation.nav.houses_all')} #{@region.name}", country_region_houses_path(@country, @region) 
    %li.divider 
    %li.nav-header Thema's 
    - @region.tags.find_each(:conditions => "active_house = true") do |a| 
    %li 
     #{link_to a.nav_content, tag_country_region_houses_path(@country, @region, a.name)} 
- elsif @country.present? 
    %li 
    %b 
    = link_to "#{t('navigation.nav.houses_all')} #{@country.name}", country_houses_path(@country) 
    %li.divider 
    %li.nav-header Thema's 
    - @country.tags.each do |a| 
    %li 
     #{link_to a.nav_content, tag_country_houses_path(a.country, a.name).capitalize} 
- else 
    %li 
    %b 
    = link_to "#{t('navigation.nav.houses_all')}", houses_path 
    %li.divider 
+0

감사 알렉스 !!!! – Remco