Skip to content

Instantly share code, notes, and snippets.

@jasonelston
Last active December 12, 2015 05:28
Show Gist options
  • Save jasonelston/4721540 to your computer and use it in GitHub Desktop.
Save jasonelston/4721540 to your computer and use it in GitHub Desktop.
Problems with Authority, RocketPants and exceptions rendered in HTML, not JSON
# Controller
class BagsController < ApiController
# ....
def index
authorize_action_for(Bag)
end
# ....
end
# API Controller
class ApiController < RocketPants::Base
include Devise::Controllers::Helpers
include ActionController::Rendering
include Authority::Controller
version 1
private
...
def current_user
User.find_for_token_authentication(:auth_token => params[:auth_token])
end
def authority_forbidden(error)
error! :forbidden #Rocketpants error method
end
end
# Should respond with json
{
"error": "forbidden",
"error_description": "The action you requested was forbidden."
}
# Responds with html 500
<!DOCTYPE html>
<html>
<head>
<title>RocketPants::Forbidden at /api/1/shoppers/3/bags</title>
<style>
/* Basic reset */
* {
margin: 0;
padding: 0;
}
table {
width: 100%;
border-collapse: collapse;
}
th, td {
vertical-align: top;
text-align: left;
}
textarea {
resize: none;
}
body {
font-size: 10pt;
}
body, td, input, textarea {
font-family: helvetica neue, lucida grande, sans-serif;
line-height: 1.5;
color: #333;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.6);
}
html {
background: #f0f0f5;
}
/* ---------------------------------------------------------------------
* Basic layout
* --------------------------------------------------------------------- */
/* Small */
@media screen and (max-width: 1100px) {
html {
overflow-y: scroll;
}
body {
margin: 0 20px;
}
header.exception {
margin: 0 -20px;
}
nav.sidebar {
padding: 0;
margin: 20px 0;
}
ul.frames {
max-height: 200px;
overflow: auto;
}
}
.... etc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment