From f24f2d15275961f1c0144e68fde75a60aeaaa165 Mon Sep 17 00:00:00 2001 From: Julio Capote Date: Mon, 23 Jan 2023 22:20:47 -0500 Subject: move to bear theme --- ...ht-link-based-on-current-page-in-rails.markdown | 30 ---------------------- 1 file changed, 30 deletions(-) delete mode 100644 content/post/2008-9-27-highlight-link-based-on-current-page-in-rails.markdown (limited to 'content/post/2008-9-27-highlight-link-based-on-current-page-in-rails.markdown') diff --git a/content/post/2008-9-27-highlight-link-based-on-current-page-in-rails.markdown b/content/post/2008-9-27-highlight-link-based-on-current-page-in-rails.markdown deleted file mode 100644 index 701b716..0000000 --- a/content/post/2008-9-27-highlight-link-based-on-current-page-in-rails.markdown +++ /dev/null @@ -1,30 +0,0 @@ ---- -title: "Highlight link based on current page in rails" -date: 2008-09-27T19:47:00Z -comments: false -url: /post/52081481/highlight-link-based-on-current-page-in-rails -tags: ---- - - - -This is common pattern in website navigation, where it highlights the link (usually by setting `class=”active”`) that took you to the current page while you are on that page. - -First, define a helper: - -```ruby -def is_active?(page_name) - "active" if params[:action] == page_name -end - -``` - -Then call it in your link_to’s in your layout as such: - -```ruby -link_to 'Home', '/', :class => is_active?("index") -link_to 'About', '/about', :class => is_active?("about") -link_to 'contact', '/contact', :class => is_active?("contact") -``` - -This effect is achieved due to how link_to handles being passed `nil` for its `:class`, so when `is_active?` returns `nil` (because its not the current page), `link_to` outputs nothing as its class (not `class=””` as you might expect). -- cgit v1.2.3