The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Site map

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Maxim Kulkin

Posts: 58
Nickname: hapk
Registered: Sep, 2006

Maxim Kulkin is developer in Selectosa Systems.
Site map Posted: Sep 10, 2006 11:02 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Maxim Kulkin.
Original Post: Site map
Feed Title: Software development
Feed URL: http://maximkulkin.blogspot.com/feeds/posts/full?alt=rss
Feed Description: Software development
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Maxim Kulkin
Latest Posts From Software development

Advertisement
How do you divide site into areas ? How do you highlight current link ?

Definition

You've got site with several navigation bars, e.g. top menu and sidebar. You want current location highlighted on both top menu and sidebar.

Analysis

Rails has link_to_unless_current method to deal with such things, but it will not be enough: it handles link to only one page, but you need the bunch of pages be linked to. Link to can become selected only on one of the page, but on others it will not be selected (because they have different urls).

Solution

My solution was to develop some site structure markup that could associate each page with some "area" or "section" or kind of..

I wrote site_map plugin that handles that:

SiteMap.draw do |map|
map.area 'member' do
map.section 'profile', :controller => 'member' do
['profile', 'profile_update',
'company_profile', 'company_profile_update'
].each do |action|
map.location :action => action
end
end
end

map.area 'admin' do
map.section 'users', :controller => 'users'
map.section 'products', :controller => 'products'
end
end

In controller and in view there is a current_location method available that returns a location descriptor - object, that has area, section, etc. values populated with names that correspond to current page. You can use it to find out what link should be "selected":

<%= link_to_if current_location.section == 'users',
'User management', :controller => 'users' %>

Read: Site map

Topic: How To: Change CSS Styles on the fly in Rails with Ajax, RJS and Prototype Previous Topic   Next Topic Topic: How-to: Ruby on Rails and Rmagick Crop, Resize, Rotate, Thumbnail and Upload Images

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use