I am learning ruby on rails, well
I have white this code to do a login and autenticate to edit post, but I dont find how to do a logout, I only can login, and then I can’t do logout, please help me
class PostsController < ApplicationController
http_basic_authenticate_with :name => 'admin', :password => 'meteoro', :except => [:index, :show]
# GET /posts
# GET /posts.json
def index
@posts = Post.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @posts }
end
end
thanks
HTTP is stateless, so it’s really a convention of the browser (client) and server that make you “logged in” for a given request. Check out the answer in this post — the important part is that once authentication is complete, the server will respond with an
Authorizationheader which the browser will pass back. Manually clearing the header in the controller by doing something likerequest.headers['Authorization'] = ''should work, I think.