Forum: Ruby on Rails application helper and tri-state images

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
73606b1d1042de19056f3d59492b652f?d=identicon&s=25 Charlie Bowman (beachguy82)
on 2006-02-27 03:51
I've come up with a very hackish way of creating a tri-state image
navbar.  I don't like it but it works pretty well.  I would love to know
the 'rails' way of doing this or even just a suggestion.  Here's my
helper.
module ApplicationHelper

  # we use this function to create the tri-state image with rollovers
  # todo I need to use a good css trick for this and not this function
  def navigation_bar
    links = [ 'home|/store/home',
              'about|/store/about',
              'necklaces|/store/browse/necklaces',
              'bracelets|/store/browse/bracelets',
              'earrings|/store/browse/earrings',
              'archives|/store/archives',
              'journal|/journal',
              'customer|/store/customer',
              'cart|/store/display_cart']
    navbar = String.new
    links.each do |link|
      image,action = link.split('|')
      if(@current_page.to_s == image)
        navbar << %Q{<img id="#{image}" src="/images/#{image}2.gif">}
      else
        navbar << %Q{<a href="#{action}"><img id="#{image}"
src="/images/#{image}.gif"
onMouseOver="this.src='/images/#{image}2.gif'"
onMouseOut="this.src='/images/#{image}.gif'"></a>}
      end
    end
    navbar
  end

end

charlie bowman
recentrambles.com
This topic is locked and can not be replied to.