Doing a Http basic authentication in rails

后端 未结 8 1060
独厮守ぢ
独厮守ぢ 2020-12-14 16:09

Hi I\'m from Grails background and new to Rails. I wish to do http basic authentication in rails.

I have a code in grails which does basic authentication like this:<

8条回答
  •  有刺的猬
    2020-12-14 16:20

    In Ruby on Rails 4 you can easily apply basic HTTP Authentication site wide or per controller depending on the context.

    For example, if you need site wide authentication:

    class ApplicationController < ActionController::Base
      http_basic_authenticate_with name: "admin", password: "hunter2"
    end
    

    Or on a per controller basis:

    class CarsController < ApplicationController
      http_basic_authenticate_with name: "admin", password: "hunter2"
    end
    

提交回复
热议问题