在RoR中将参数传递给CanCan [英] Passing params to CanCan in RoR

查看:69
本文介绍了在RoR中将参数传递给CanCan的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个控制器,其方法类似;

I have a controller with a method like;

def show

    if params[:format].eql?("pdf")
    // do something
    elsif params[:format].eql?("csv")
    // do something
    end
end

但是我有不同角色的用户。因此,我使用CanCan来管理访问控制。
现在我希望X角色可以在控制器iff params [:format] .eql?( csv)<中执行动作 show / code>

But i have users with different roles. So i use CanCan to manage access control. Now i want X role can do the action show in controller iff params[:format].eql?("csv")

我认为它可能像; can:show,if params [:format] .eql? csv)。那么我该如何将参数发送到Capacity.rb?

I think it can be like ;can :show, resource if params[:format].eql?("csv"). So how can i send parameters to ability.rb?

任何想法吗?

谢谢。

推荐答案

在ApplicationController中添加以下内容:

In ApplicationController add the following:

# CanCan - pass params in to Ability
# https://github.com/ryanb/cancan/issues/133
def current_ability
  @current_ability ||= Ability.new(current_user, params)
end

这篇关于在RoR中将参数传递给CanCan的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆