0

Given the following example from the CanCan wiki,

https://github.com/ryanb/cancan/wiki/Admin-Namespace

How would I do a can? check within a view for the namespaced article controller.
For the purpose of this, imagine the ability.rb file states the current user.role is able to view an article, and the admin_ability.rb states the user can create an article

<% if can? :read, Articles %>
  I can view an article
<% end %>


<% if can? :create, Articles %>
  I can create an article
<% end %>

I don't know how to get the latter to work. It would be neat if I could specify the namespace on it perhaps such as

<% if admin::can? :create, Articles %>

But I am not sure what the syntax would be if that were possible.

Rails Fan
  • 121
  • 1
  • 12
  • Duplicate of [Authorizing Namespaced and Nested controllers using CanCan](http://stackoverflow.com/questions/12334367/authorizing-namespaced-and-nested-controllers-using-cancan). Only question 12334367 has the correct answer to this common question. – Jared Beck Jun 02 '13 at 17:50

2 Answers2

2

I don't think Marc's suggestion will work. Checkout this wiki from Ryan. https://github.com/ryanb/cancan/wiki/Admin-Namespace

GeorgeW
  • 566
  • 5
  • 17
0

Have you tried:

<% if can? :create, Admin::Articles %>
Marc
  • 2,584
  • 5
  • 33
  • 47