Rails: Return a 401?
You can add the :status
option
def permission_denied render :file => "public/401.html", :status => :unauthorizedend
Here so you don't have to dig through comments for a modern answer.
The previous answer has been deprecated in Rails 5.1
Throw any of these into your controller action:
Render A File/Template
render :file => "public/401", :status => :unauthorized
Render JSON
render status: :unauthorized, json: { error: "You are not authorized to access this resource. Verify that you are passing passing your token." }
Render Nothing
head :unauthorized