Add framework for parameter validation using rails_param gem
This commit is contained in:
parent
ba90fe97ea
commit
feff501b25
9 changed files with 70 additions and 0 deletions
|
@ -10,6 +10,8 @@ class ApplicationController < ActionController::Base
|
|||
rescue_from CanCan::AccessDenied, :with => :deny_access
|
||||
check_authorization
|
||||
|
||||
rescue_from RailsParam::InvalidParameterError, :with => :invalid_parameter
|
||||
|
||||
before_action :fetch_body
|
||||
around_action :better_errors_allow_inline, :if => proc { Rails.env.development? }
|
||||
|
||||
|
@ -306,6 +308,17 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
end
|
||||
|
||||
def invalid_parameter(_exception)
|
||||
if request.get?
|
||||
respond_to do |format|
|
||||
format.html { redirect_to :controller => "/errors", :action => "bad_request" }
|
||||
format.any { head :bad_request }
|
||||
end
|
||||
else
|
||||
head :bad_request
|
||||
end
|
||||
end
|
||||
|
||||
# extract authorisation credentials from headers, returns user = nil if none
|
||||
def auth_data
|
||||
if request.env.key? "X-HTTP_AUTHORIZATION" # where mod_rewrite might have put it
|
||||
|
|
|
@ -5,6 +5,13 @@ class ErrorsController < ApplicationController
|
|||
|
||||
before_action :set_locale
|
||||
|
||||
def bad_request
|
||||
respond_to do |format|
|
||||
format.html { render :status => :bad_request }
|
||||
format.any { render :status => :bad_request, :plain => "" }
|
||||
end
|
||||
end
|
||||
|
||||
def forbidden
|
||||
respond_to do |format|
|
||||
format.html { render :status => :forbidden }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue