Socket
Book a DemoInstallSign in
Socket

rails_navigation

Package Overview
Dependencies
Maintainers
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rails_navigation

0.0.3
bundlerRubygems
Version published
Maintainers
2
Created
Source

Gem Version Build Status Code Climate

rails_navigation

Simplify matching of Rails routes. You are unhappy with the link_to_if helper?

Then check out this gem! You can now match controllers and actions as they are defined in your routes.rb.

Installation

Add this line to your application's Gemfile:

gem 'rails_navigation'

And then execute:

$ bundle

Usage

matches_page?

Works like current_page? Example:

matches_page?('controller#action')

with multiple conditions:

matches_page?(['controller#action', 'other_controller#action'])

nav_to

Uses matches_page? and creates a link and a li element

Source code, if you want to customize it:

def nav_to(name, path, conditions = nil)
 content_tag :li, link_to(name, path), class: ('active' if matches_page?(conditions))
end

Examples

You have a webseite full of books and want to show an edit button on the books#show page.

matches_page?('books#show')

It's like your routes.rb

Matching controllers:

{ controller: "pages" } becomes 'pages'  

Matching controllers and actions:

{ controller: "pages", action: "new" } becomes 'pages#new'  

Matching controllers, actions and params:

{ controller: "pages", action: "show", params: { id: 'homepage' } } becomes 'pages#new?id=homepage'
    

Or even simpler (id is the default):

{ controller: "pages", action: "show", params: { id: 'homepage' } } becomes 'pages#new?homepage'  

What it does:

rails_navigation adds 2 helpers

  • matches_page?(conditions)
  • nav_to(name, path, conditions)

TODO

  • support not operator
  • html options for inner link element

Maintainers

Contributing

  • Fork it ( https://github.com/sbrink/rails_navigation/fork )
  • Create your feature branch (git checkout -b my-new-feature)
  • Commit your changes (git commit -am 'Add some feature')
  • Push to the branch (git push origin my-new-feature)
  • Create a new Pull Request

FAQs

Package last updated on 20 Jun 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.