Home:ALL Converter>Can Can with Role Model restriction

Can Can with Role Model restriction

Ask Time:2013-12-02T17:10:03         Author:Mini John

Json Formatter

I'm Trying to achieve that the user can see only HIS applications, and not the "Application Index" containing all the applications from all Users.

My Header:

 <%= link_to "My Application ", current_user.application %>

My Abilities:

 if user.has_role? :speaker
  can :read, Application do |application| # heres the problem
    application.try(:user) == user
  can :create, Application
  can :update, Application do |application|
    application.try(:user) == user

Currently the User can access the Application/Index page. But the restriction should give him only access to:

http://localhost:3000/applications/8 # 8 being his application

What am i missing ?

Author:Mini John,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/20324495/can-can-with-role-model-restriction