0

Im new to rails.. Im trying to implement basic auth for show action in post model generated by scaffold..I have 2 doubts..

  1. 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

  2. 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
  • could you read this https://stackoverflow.com/questions/15662969/what-is-the-difference-between-http-basic-authenticate-with-and-authenticate-or#15663265 and give me feedback – Fabrizio Bertoglio Nov 15 '17 at 09:17
  • I have gone through this, but there are issues with authenticate_or_request_with_http_basic, only first time it works after that it get same response again and again until i restart my server – Harish Ramesh Nov 15 '17 at 09:52

0 Answers0