Forum: Ruby on Rails Navigation

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
C4fee92c07e4fee216aeab5be40e6cc9?d=identicon&s=25 Naga harish Kanegolla (nagaharish)
on 2006-12-27 14:20
Hi all,
  Is there any way of doing Navigation using Rails. Such that if we are
in controller "xyz" and action "abc", then we should not get the link of
"xyz" given in the layout. It should be hidden. I did this using hard
coding by writing if condition. But is there any other method to do
8b22ad683842861ba91f68d5d32954db?d=identicon&s=25 Jason Norris (Guest)
on 2006-12-27 15:12
(Received via mailing list)
instead of link_to, use link_to_unless_current
this will still display the text, but it won't be a link. If you want
the text to be hidden, you could write your own method to do it.
I would look at the source for link_to_unless

172:       def link_to_unless(condition, name, options = {},
html_options = {}, *parameters_for_method_reference, &block)
173:         if condition
174:           if block_given?
175:             block.arity <= 1 ? yield(name) : yield(name, options,
html_options, *parameters_for_method_reference)
176:           else
177:             name
178:           end
179:         else
180:           link_to(name, options, html_options,
181:         end
182:       end

and link_to_unless_current

166:       def link_to_unless_current(name, options = {}, html_options =
{}, *parameters_for_method_reference, &block)
167:         link_to_unless current_page?(options), name, options,
html_options, *parameters_for_method_reference, &block
168:       end
This topic is locked and can not be replied to.