I implemented a static page with ruby on rails that shows all the stats related to my work. I can deploy to the admin page but it requires username/pwd which is annoying. So I want a static page with simple authentication like 4 digits of codes or only some devices and access it. Any suggestion?
add a basic authentication method on your app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
...
private
def authenticate
authenticate_or_request_with_http_basic do |username, password|
username == "admin" && password == "admin"
end
end
end
Then add a before_filter
(or before_action
for rails5) callback on any controller you want to use this authentication.
For example, if you want to authenticate to access reports
action from PagesController
class PagesController < ApplicationController
before_filter :authenticate, only: [:report]
def about
end
def report
end
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.