devise

rails_admin with cancan not catching access denied exception for redirect

落花浮王杯 提交于 2020-08-27 07:07:10
问题 I am using rails 5, rails_admin, devise and cancancan. Everything works correctly, but when there is access denied, it shows a 'You are not authorized to access this page' error screen. I want to redirect to root_path, I've been searching and I only found that I have to write in app/controllers/application_controller.rb this code: class ApplicationController < ActionController::Base rescue_from CanCan::AccessDenied do |exception| redirect_to root_path, :alert => exception.message end end And

rails_admin with cancan not catching access denied exception for redirect

假装没事ソ 提交于 2020-08-27 07:07:05
问题 I am using rails 5, rails_admin, devise and cancancan. Everything works correctly, but when there is access denied, it shows a 'You are not authorized to access this page' error screen. I want to redirect to root_path, I've been searching and I only found that I have to write in app/controllers/application_controller.rb this code: class ApplicationController < ActionController::Base rescue_from CanCan::AccessDenied do |exception| redirect_to root_path, :alert => exception.message end end And

How to define custom Failure for devise in case of two different models User and active admin?

随声附和 提交于 2020-08-22 05:38:36
问题 I have two models User and ActiveAdmin on which I want to apply my devise integrations. I have my custom_failure.rb as follows class CustomFailure < Devise::FailureApp def redirect_url login_path end # def redirect_url # root_path # end def respond if http_auth? http_auth else redirect end end end Which seems to be working great. Also, can define in my application controller like : def after_sign_in_path_for(resource) # case resource if resource.is_a?(Admin) admin_dashboard_path else root

API signin to generate token using devise in rails 4

大憨熊 提交于 2020-08-05 10:57:24
问题 I am implementing api via rails. I want to implement following feature but unable to figure out how? I tried this sample app I have user model with email, password and access_token class UsersController < ApplicationController def signin c_user = User.find_by_email(params[:email]) pass = params[:password] if c_user.password == pass render json: c_user.access_token end end private def users_params params.require(:user).permit(:email, :password) end end If user request via api for http:/