rails 4.2.6 authenticate_or_request_with_http_basic problems in update/put/patch method

176 Views Asked by At

Hi guys i have problems with authenticate_or_request_with_http_basic, here is the code:

def authenticate
  puts "here 1"
  if authenticate_or_request_with_http_basic('Qontak') do |username, password|
      puts "here 2"
      @user = User.find_by(public_key: username, private_key: password)
    end
  else
    puts "here 3"
    render json: {message: 'Unauthorized'}
  end
  puts "here 4"
end

when i debug for update method the console prints out:

here 1
here 4

Then there is error log like this:

Filter chain halted as :authenticate rendered or redirected
Completed 401 Unauthorized in 19ms (ActiveRecord: 2.2ms)

after that i was redirected to show route and the console successfully printed like this one

here 1
here 2
here 4

i was wondering what happened to put/patch/update method while authentication ? why it fails but not show/get route ?

0

There are 0 best solutions below