Doing a Http basic authentication in rails

后端 未结 8 1098
独厮守ぢ
独厮守ぢ 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:31

    I upvoted @Nishant's answer but wanted to add another tidbit. You can always set filters so it only applies to certain controller actions by passing only or except like so:

    http_basic_authenticate_with name: "admin", password: "strongpasswordhere", only: [:admin, :new, :edit, :destroy]

    or

    http_basic_authenticate_with name: "admin", password: "strongpasswordhere", except: [:show]

    Very helpful in many instances.

提交回复
热议问题