CanCanCan, Devise & Rolify를 사용하고 있습니다.CanCanCan이 지정된 것처럼 플래시 메시지가 아닌 예외에 일반 레일 오류를 발생시킵니다.
내 ApplicationController
은 다음과 같습니다
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
before_filter :new_post
rescue_from CanCan::AccessDenied do |exception|
redirect_to root_url, :alert => exception.message
end
def new_post
@post = Post.new
end
end
내 routes.rb
은 다음과 같습니다
elsif user.has_role? :member
can :read, :all
cannot :read, :newsroom
그래서 내가 로그인 한 경우 :
이authenticate :user, lambda { |u| u.has_role? :admin or :editor } do
get 'newsroom', to: 'newsroom#index', as: "newsroom"
get 'newsroom/published', to: 'newsroom#published'
get 'newsroom/unpublished', to: 'newsroom#unpublished'
end
# truncated for brevity
root to: "posts#index"
이 관련 내 ability.rb
입니다 안으로 :member
, 그리고 나는에 간다 내가 기대 한 것처럼
NameError at /newsroom
uninitialized constant Newsroom
보다는
가:alert
로
root_url
로 리디렉션되는 :
/newsroom
, 나는이 오류가 발생합니다.
여기 무슨 일인지 잘 모르겠습니다.
내 NewsroomController
이를 추가 할 때 편집 한 그것은 가치가 무엇인지에 대한
, 나는 단지이 얻을 :
authorize_resource
이 오류를 유발 하는가 – Typpex
@Typpex 예는 d를 oes는 admin으로 로그인 한'/ newsroom'에 접근하면 에러를 발생시킵니다. – marcamillion