devise

https://github.com/plataformatec/devise

Ruby

Flexible authentication solution for Rails with Warden.

ActionDispatch::Routing::Mapper#authenticate

Allow you to add authentication request from the router.
Takes an optional scope and block to provide constraints
on the model instance itself.

  authenticate do
    resources :post
  end

  authenticate(:admin) do
    resources :users
  end

  authenticate :user, lambda {|u| u.role == "admin"} do
    root to: "admin/dashboard#show", as: :user_root
  end

Source | Google | Stack overflow

Edit

git clone [email protected]:plataformatec/devise.git

cd devise

open lib/devise/rails/routes.rb

Contribute

# Make a new branch

git checkout -b -your-name--update-docs-ActionDispatch--Routing--Mapper-authenticate-for-pr


# Commit to git

git add lib/devise/rails/routes.rbgit commit -m "better docs for ActionDispatch::Routing::Mapper#authenticate"


# Open pull request

gem install hub # on a mac you can `brew install hub`

hub fork

git push <your name> -your-name--update-docs-ActionDispatch--Routing--Mapper-authenticate-for-pr

hub pull-request


# Celebrate!