{"id":13427967,"url":"https://github.com/comfy/active_link_to","last_synced_at":"2025-05-14T15:07:34.525Z","repository":{"id":552767,"uuid":"1400705","full_name":"comfy/active_link_to","owner":"comfy","description":"Rails view helper to manage \"active\" state of a link","archived":false,"fork":false,"pushed_at":"2024-04-07T09:40:49.000Z","size":83,"stargazers_count":854,"open_issues_count":9,"forks_count":82,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-14T20:55:20.693Z","etag":null,"topics":["navigation","rails"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/comfy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2011-02-23T02:39:36.000Z","updated_at":"2025-04-08T13:38:22.000Z","dependencies_parsed_at":"2024-05-01T13:20:21.720Z","dependency_job_id":"87371f24-622a-4894-8a95-4b0151752186","html_url":"https://github.com/comfy/active_link_to","commit_stats":{"total_commits":95,"total_committers":18,"mean_commits":5.277777777777778,"dds":0.6,"last_synced_commit":"0726773f543113186a36e0094fef718cbd98cad4"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/comfy%2Factive_link_to","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/comfy%2Factive_link_to/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/comfy%2Factive_link_to/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/comfy%2Factive_link_to/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/comfy","download_url":"https://codeload.github.com/comfy/active_link_to/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254169735,"owners_count":22026214,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["navigation","rails"],"created_at":"2024-07-31T01:00:43.593Z","updated_at":"2025-05-14T15:07:34.493Z","avatar_url":"https://github.com/comfy.png","language":"Ruby","funding_links":[],"categories":["View Helper","Ruby","View helpers","视图","Navigation"],"sub_categories":["Omniauth"],"readme":"# active_link_to\n\nCreates a link tag of the given name using a URL created by the set of options. Please see documentation for [link_to](http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to), as `active_link_to` is basically a wrapper for it. This method accepts an optional :active parameter that dictates if the given link will have an extra css class attached that marks it as 'active'.\n\n[![Gem Version](https://img.shields.io/gem/v/active_link_to.svg?style=flat)](http://rubygems.org/gems/active_link_to)\n[![Gem Downloads](https://img.shields.io/gem/dt/active_link_to.svg?style=flat)](http://rubygems.org/gems/active_link_to)\n[![Build Status](https://img.shields.io/travis/comfy/active_link_to.svg?style=flat)](https://travis-ci.org/comfy/active_link_to)\n[![Gitter](https://badges.gitter.im/comfy/comfortable-mexican-sofa.svg)](https://gitter.im/comfy/comfortable-mexican-sofa)\n\n## Install\nWhen installing for Rails 3/4/5 applications add this to the Gemfile: `gem 'active_link_to'` and run `bundle install`.\n\nFor older Rails apps add `config.gem 'active_link_to'` in config/environment.rb and run `rake gems:install`. Or just checkout this repo into /vendor/plugins directory.\n\n## Super Simple Example\nHere's a link that will have a class attached if it happens to be rendered\non page with path `/users` or any child of that page, like `/users/123`\n\n```ruby\nactive_link_to 'Users', '/users'\n# =\u003e \u003ca href=\"/users\" class=\"active\"\u003eUsers\u003c/a\u003e\n```\n\nThis is exactly the same as:\n\n```ruby\nactive_link_to 'Users', '/users', active: :inclusive\n# =\u003e \u003ca href=\"/users\" class=\"active\"\u003eUsers\u003c/a\u003e\n```\n\n## Active Options\nHere's a list of available options that can be used as the `:active` value\n\n```\n* Boolean                         -\u003e true | false\n* Symbol                          -\u003e :exclusive | :inclusive | :exact\n* Regex                           -\u003e /regex/\n* Controller/Action Pair          -\u003e [[:controller], [:action_a, :action_b]]\n* Controller/Specific Action Pair -\u003e [controller: :action_a, controller_b: :action_b]\n* Hash                            -\u003e { param_a: 1, param_b: 2 }\n```\n\n## More Examples\nMost of the functionality of `active_link_to` depends on the current\nurl. Specifically, `request.original_fullpath` value. We covered the basic example\nalready, so let's try something more fun.\n\nWe want to highlight a link that matches immediate url, but not the children\nnodes. Most commonly used for 'home' links.\n\n```ruby\n# For URL: /users will be active\nactive_link_to 'Users', users_path, active: :exclusive\n# =\u003e \u003ca href=\"/users\" class=\"active\"\u003eUsers\u003c/a\u003e\n```\n\n```ruby\n# But for URL: /users/123 it will not be active\nactive_link_to 'Users', users_path, active: :exclusive\n# =\u003e \u003ca href=\"/users\"\u003eUsers\u003c/a\u003e\n```\n\nIf we need to set link to be active based on some regular expression, we can do\nthat as well. Let's try to activate links urls of which begin with 'use':\n\n```ruby\nactive_link_to 'Users', users_path, active: /^\\/use/\n```\n\nIf we need to set link to be active based on an exact match, for example on\nfilter made via a query string, we can do that as well:\n\n```ruby\nactive_link_to 'Users', users_path(role_eq: 'admin'), active: :exact\n```\n\nWhat if we need to mark link active for all URLs that match a particular controller,\nor action, or both? Or any number of those at the same time? Sure, why not:\n\n```ruby\n# For matching multiple controllers and actions:\nactive_link_to 'User Edit', edit_user_path(@user), active: [['people', 'news'], ['show', 'edit']]\n\n# For matching specific controllers and actions:\nactive_link_to 'User Edit', edit_user_path(@user), active: [people: :show, news: :edit]\n\n# for matching all actions under given controllers:\nactive_link_to 'User Edit', edit_user_path(@user), active: [['people', 'news'], []]\n\n# for matching all controllers for a particular action\nactive_link_to 'User Edit', edit_user_path(@user), active: [[], ['edit']]\n```\n\nSometimes it should be as easy as giving link true or false value:\n\n```ruby\nactive_link_to 'Users', users_path, active: true\n```\n\nIf we need to set link to be active based on `params`, we can do that as well:\n\n```ruby\nactive_link_to 'Admin users', users_path(role_eq: 'admin'), active: { role_eq: 'admin' }\n```\n\n## More Options\nYou can specify active and inactive css classes for links:\n\n```ruby\nactive_link_to 'Users', users_path, class_active: 'enabled'\n# =\u003e \u003ca href=\"/users\" class=\"enabled\"\u003eUsers\u003c/a\u003e\n\nactive_link_to 'News', news_path, class_inactive: 'disabled'\n# =\u003e \u003ca href=\"/news\" class=\"disabled\"\u003eNews\u003c/a\u003e\n```\n\nSometimes you want to replace link tag with a span if it's active:\n\n```ruby\nactive_link_to 'Users', users_path, active_disable: true\n# =\u003e \u003cspan class=\"active\"\u003eUsers\u003c/span\u003e\n```\n\nIf you are constructing navigation menu it might be helpful to wrap links in another tag, like `\u003cli\u003e`:\n\n```ruby\nactive_link_to 'Users', users_path, wrap_tag: :li\n# =\u003e \u003cli class=\"active\"\u003e\u003ca href=\"/users\"\u003eUsers\u003c/a\u003e\u003c/li\u003e\n```\n\nYou can specify css classes for the `wrap_tag`:\n\n```ruby\nactive_link_to 'Users', users_path, wrap_tag: :li, wrap_class: 'nav-item'\n# =\u003e \u003cli class=\"nav-item active\"\u003e\u003ca href=\"/users\"\u003eUsers\u003c/a\u003e\u003c/li\u003e\n```\n\n## Helper Methods\nYou may directly use methods that `active_link_to` relies on.\n\n`is_active_link?` will return true or false based on the URL and value of the `:active` parameter:\n\n```ruby\nis_active_link?(users_path, :inclusive)\n# =\u003e true\n```\n\n`active_link_to_class` will return the css class:\n\n```\nactive_link_to_class(users_path, active: :inclusive)\n# =\u003e 'active'\n```\n\n### Copyright\n\nCopyright (c) 2009-18 Oleg Khabarov. See LICENSE for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcomfy%2Factive_link_to","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcomfy%2Factive_link_to","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcomfy%2Factive_link_to/lists"}