Im new to rails.. Im trying to implement basic auth for show action in post model generated by scaffold..I have 2 doubts..
authenticate_or_request_with_http_basic Only first time it asks for username and password, everytime i need to restart browser for dialog box to appear. if solution for this, reply
authenticate_or_request_with_http_basic It gives first response everytime, I have to everytime restart server to see effects for my change in post controller.
I will Post my Code in following..
Post Controller
class PostsController < ApplicationController
before_action :authenticate_user, only: [:show]
before_action :set_post, only: [:show]
# GET /posts/1
# GET /posts/1.json
def show
respond_to do |format|
format.json {render json: {:post => @post, status: 200}}
format.html {}
end
def authenticate_user
authenticate_or_request_with_http_basic do |u, p|
if u=="h"
if p=="h"
true
end
end
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_post
@post = Post.find(params[:id])
end