Question

The scenario/objective is:

When the visitor is on the homepage the links in head navigation are these: "Villas", "Apartments", "B&B" When the visitor is on the country page (example: en/italy) the links in head navigation are these: "Villas Italy", "Apartments Italy", "B&B Italy" When the visitor is on the region page (example: en/italy/tuscany) the links in head navigation are these: "Villas Tuscany", "Apartments Tuscany", "B&B Tuscany"

This is my code:

%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

So want i want to realize is when the @region value is set i want to show a part of the nav @country value is set i want to show another part. But when i am on the region page (en/italy/tuscany) is shows also the @country nav part because @country is also set.

How can i fix this?

Was it helpful?

Solution

If what you want is to only show the @country menu if there is no @region menu, you can try with an 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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top