난 내 rails-App에 문제가 있습니다. 나는 cancan을 사용하여 특정 사용자의 링크를 숨 깁니다. 오류가 발생하지 않으며 사용자의 역할이 올바르게 인식됩니다. 그러나 내가 시도한 것은 무엇이든 내 링크는 결코 보여지지 않습니다. can? - Method는 항상 true를 반환합니다.레일 3.1 : 수 있습니까? 메서드는 항상 false를 반환합니다.
class Ability
include CanCan::Ability
def initialize(user)
current_user ||= User.new # guest user (not logged in)
puts "Debug"
if current_user.role?(:Admin)
can :manage, Prof
else
if current_user.role?(:Proff)
can :manage, [Exam, Note, Student,Break,Appointment]
else
if current_user.role?(:Student)
can :update, Appointment
can :show, Exam
end
end
end
end
end
이 내 시야에서이다 : 다음 @exam이 definitly nil이 아닌 이 내 능력 클래스입니다. 나는 또한 시험을 시도하고 : 시험, 아무것도 작동하지 않습니다. 이 중요하지만, 내 컨트롤러의 머리를 먹으 렴 경우
<% if can? :edit, @exam%>
<%= link_to 'Bearbeiten', edit_exam_path(@exam) %> |
<%= link_to 'Alle Prüfungen', exams_path %>
<% end%>
내가 알고하지는 :
class ExamsController < ApplicationController
before_filter :login_required
skip_authorization_check
...
내 시험 모델 : 콘솔에서
class Exam < ActiveRecord::Base
belongs_to :prof
validates_presence_of :prof_id,:title,:deadline
has_many :examdates, :dependent => :destroy
accepts_nested_attributes_for :examdates,
:allow_destroy => true#, :reject_if => proc {| a| a[:date].blank? }
end
나는
시도Exam.accessible_by(ability)
그리고 []가 있습니다. Cancan 1.6.7, 레일 3.1.0 및 루비 1.8.7을 사용하고 있습니다.
나는 누군가가 알아낼 수 있기를 정말로 바란다. 나는 틀린 일을하고있다.
미리 감사드립니다.
보면'? (: PROFF)? (: 교수)''는'경우를 current_user.role 안? – tommasop
아니요, 저는 두 개의 ffs를 사용하여 역할을 명명했습니다. 모델 교수가 있었고 충돌이 필요하지 않았기 때문입니다. 그것이 nessecary인지 확실하지 않습니다. –
이 'skip_authorization_check' 권한 부여 검사를 건너 뛰지 않습니다 ??? 콘솔에 – tommasop