And*_*rew 2 authorization ruby-on-rails cancan ruby-on-rails-3
所以,我正在使用Rails 3和CanCan进行授权.我希望所有用户都能删除他们创建的照片,我想我已经正确设置了这个,但是它无法正常工作......
这是我的能力课:
class Ability
include CanCan::Ability
def initialize(user)
# ONLY REGISTERED USERS CAN DO THESE THINGS
unless user.nil?
# ALL REGISTERED USERS CAN DO THESE THINGS
can :read, [Photo, Context, Focus, LandUse, Vote, Rating, Comment, Profile, Article]
can :show, Page
# MEMBERS
if user.has_role? :member
can [:create, :read], Photo
can [:update, :destroy], Photo, :user_id => user.id
can :create, [Vote, Rating, Comment, Profile]
can :update, [Vote, Rating, Comment, Profile], :user_id => user.id
can [:show, :update], User do |u|
u == user
end
end
# CURATORS
...
# ADMINS
...
end
# ALL VISITORS CAN DO THESE THINGS
can :create, [User, Profile]
can :request_invite, User
# can :show, Page
end
end
Run Code Online (Sandbox Code Playgroud)
这是我的控制器动作:
def destroy
@photo = Photo.find(params[:id])
authorize! :delete, @photo
@photo.destroy
redirect_to :back, :notice => 'Photo deleted.'
end
Run Code Online (Sandbox Code Playgroud)
任何想法在这里出了什么问题?
| 归档时间: |
|
| 查看次数: |
2382 次 |
| 最近记录: |