管理员登录并创建了与项目相关的票证,然后正确上传了一个附件,没有错误,然后当我尝试下载它时,它进入错误状态,当我替换can?
为cannot?
他能够下载资产时,需要做什么管理员能够在不更改当前控制器显示操作的情况下下载它吗?
注意:如果用户没有查看资产的权限,它应该发生的错误情况,但我不知道这怎么会发生在管理员身上,也无法在书中找到它。有没有人经历过这个?
class FilesController < ApplicationController
before_filter :authenticate_user!
def show
asset = Asset.find(params[:id])
if can?(:view, asset.ticket.project)
send_file asset.asset.path, :filename => asset.asset_file_name,
:content_type => asset.asset_content_type
else
flash[:alert] = "The asset you were looking for could not be found."
redirect_to root_path
end
end
end
能力.rb
class Ability
include CanCan::Ability
def initialize(user)
user.permissions.each do |permission|
can permission.action.to_sym, permission.thing_type.constantize do |thing|
thing.nil? || permission.thing_id.nil? || permission.thing_id == thing.id
end
end
end
end