Skip to content

Instantly share code, notes, and snippets.

@MaksimAbramchuk
Created August 11, 2014 15:21
Show Gist options
  • Save MaksimAbramchuk/93be6c198a28eba5d8df to your computer and use it in GitHub Desktop.
Save MaksimAbramchuk/93be6c198a28eba5d8df to your computer and use it in GitHub Desktop.
app_controller
require 'app_responder'
class ApplicationController < ActionController::Base
include Pundit
protect_from_forgery with: :exception
before_action :authenticate_user!
before_action :configure_permitted_parameters, if: :devise_controller?
self.responder = AppResponder
respond_to :html
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
private
def user_not_authorized
flash[:alert] = t('errors.not_authorized')
redirect_to root_path
end
def raise_not_found_if_blank!(record)
if record.blank?
raise ActiveRecord::RecordNotFound
end
end
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) << [:first_name, :last_name]
devise_parameter_sanitizer.for(:account_update) do |u|
u.permit(:first_name, :last_name, :email, :password, :password_confirmation, :current_password, contact_information_attributes: [:id, :phone_number, :_destroy])
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment