私は自分のレールアプリに問題があります。私はcancanを使用して、特定のユーザーからのリンクを隠すことができます。 エラーが発生せず、ユーザーの役割が正しく認識されています。しかし、私が何をしようと、私のリンクは決して表示されません。 can?-Methodは常にtrueを返します。 これは私の能力クラスです:Rails 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は間違いなくnilでありません。私も試験に合格しました:試験、何も動作しません。これは重要ですが、私のコントローラの頭のthats場合
<% 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、rails 3.1.0とruby 1.8.7を使用しています。
本当に、私が間違っていることを誰かが理解できることを願っています。
ありがとうございます!
' current_user.role場合を見て? – tommasop
いいえ、私はちょうどモデルProfを持っているので、2つのffsを使ってロールに名前を付けました。もしそれが必ずしも確実ではない。 –
はこの 'skip_authorization_check'では認証チェックをスキップしていませんか?コンソールの – tommasop