Take the 2-minute tour ×

When trying to request JSON from a resource not owned by a User, despite the validation I wrote below, the JSON shows up as empty brackets, but the status comes back as 200 OK. What do I need to change to respond with a 401 status:

    @requested_resource = params[:resource_id].to_i
    @users_resources = Resource.owned_by(@current_user.id).collect {|s| s.id}
    if @users_resources.include?(@requested_resource)

      respond_to do |format|
        format.json { render :json => [], :status => :unauthorized }
        format.html { render :file => "public/401.html", :status => :unauthorized }

Also, I am using RABL...

share|improve this question

1 Answer 1

Let RoR play the game for you, use redirect_to instead of respond_to. E.g.:

redirect_to "public/401.html", :alert => "Please authorize", :status => :unauthorized
share|improve this answer
Switching to redirect_to results in a 304 Not Modified Status. –  ac360 Apr 8 '13 at 3:53
I’ve updated an answer with what’s working for me. –  mudasobwa Apr 8 '13 at 4:00
Hmmm, with your new answer the status goes back to 200 OK. It must be either the IF Statement or the fact that I'm using RABL –  ac360 Apr 8 '13 at 4:04
In fact, RABL shouldn’t bring smth to redirection. Maybe this would help you? –  mudasobwa Apr 8 '13 at 4:11

Your Answer


