I'm using Rails 2.3.11 with cancan 1.1.
I want to add a new role that would allow the user to create/edit 'publications' and create/edit 'articles' in those 'publications' that belong to one specific Organization. As I mentioned, I could not try all the new examples in the doc due to the fact that I'm running the older cancan 1.1. This is an example of what I tried in Ability.rb:
class Ability
include CanCan::Ability
#additional roles require changes be made to config/environment.rb ROLES constant
def initialize(user)
user ||= User.new # Guest user
# Multirole environment
if user.role? :admin
can :manage, :all
can :archive, Article
can :review, Article
end
#several other roles ...
#This is not working...I'm specify the organization that I want the super_user to be able to create and edit for
if user.role? :super_user
can [:create, :edit], Publication, :organization_id => 21
can [:create, :edit], Article, :organization_id => 21
end
I have the following three models:
class Organization < ActiveRecord::Base
#validations here
has_many :publications, :dependent => :destroy
has_many :articles, :through => :publications
end
class Publication < ActiveRecord::Base
#validations here
has_many :articles, :dependent => :destroy
end
class Article < ActiveRecord::Base
#validations here ...
belongs_to :publication
validates_associated :publication
#...
end
Thank you for any suggestions.