Rails: return 401?

I want to return an HTTP 401 error as part of my permission_denied method for declarative_authorization .

 # triggered when a user accesses a page that they don't have access to def permission_denied # render my default 401 error page? end 

How should I do it? (Pardon the question if this is stupid ... I know how to make the 401.html page in my public directory, but I don’t think it returns the 401 HTTP header, and that’s what I follow.)

+46
ruby-on-rails
Jan 16 2018-10-10T00: 00Z
source share
1 answer

You can add an option :status

 def permission_denied render :file => "public/401.html", :status => :unauthorized end 
+77
Jan 16 '10 at 0:32
source share



All Articles