mardi 10 mars 2015

Authorize controller actions with cancan in rails

i have some actions in controller and put authorize for 3 actions,



class TestController
def test1
authorize! :view, :testcase1
#do things1
end

def test2
authorize! :view, :testcase2
#do things2
end

def test3
authorize! :view, :testcase3
#do things3
end
end


and in the corresponding action's view, i am checking like this



if can? :view, :test_case1
#do things
end


So the problem is i am calling the authorize in 3 functions, can i put it like a single, same as before_filter


Aucun commentaire:

Enregistrer un commentaire