0

在我的Rails 4项目中,我有一个引擎Blorgh,我根据Rails Guides 制作然后我将它安装到我的应用程序中。一切都很好,没有问题。当我在安装的引擎中使用声明性授权时出现重定向错误

我目前的应用程序使用declarative_authorization。它在我的应用程序内工作正常。 当我在引擎控制器中使用filter_resource_access时,出现重定向错误。

登录权限后否认:

: Redirected to http://0.0.0.0:3000/blog/ 
: Filter chain halted as :filter_access_filter rendered or redirected 
: Completed 302 Found in 3ms (ActiveRecord: 0.3ms) 

谢谢你们。

有些代码: 引擎application_controller.rb

module Blorgh 
    class ApplicationController < ActionController::ApplicationController 
    end 
end 

引擎posts_controller.rb

module Blorgh 
    class PostsController < ApplicationController 
    before_action :set_post, only: [:show, :edit, :update, :destroy]  
    filter_resource_access 
... 

引擎的routes.rb

Blorgh::Engine.routes.draw do 
    resources :posts do 
     resources :comments 
    end 
    root to: "posts#index" 
end 

应用的routes.rb

mount Blorgh::Engine, at: "/blog" 

除了引擎中的filter_resource_access,一切都是非凡的。 current_user.inspect引擎控制器返回正确的输出,这意味着我可以通过引擎访问应用程序中的方法。只需要找出当filter_resource_access返回权限被拒绝时如何将用户重定向到应用程序主目录。

如果您需要更多代码,请让我知道。

再次感谢。

+0

你可能想要发布一些实际的代码。从你所说的话很难猜出发生了什么 – Nikolay

回答

1

好的,我找到了重定向的解决方案。

在任何情况下都有一个相同的问题:

在application_controller.rb

:在main_app添加到root_url(application_controller.rb主应用程序)

before_filter { |c| Authorization.current_user = c.current_user } 
    def permission_denied 
    flash[:error] = "Sorry, you are not allowed to access that page."; 
    redirect_to main_app.root_url 
    end 

欢呼

相关问题