views:

34

answers:

1

I'm using the Rails Plugin CanCan to handle permissions checks.

I have the following in ability.rb:

def initialize(user, projectid_viewing) 
 user ||= User.new
 if projectid_viewing == 8
  can :manage, :all
 else
  can :read, :all  
 end
end

The projectid_viewing is being sent from:

class ProjectsController < ApplicationController
 before_filter :prepareCanCan, :only => [:show, :edit]
  def prepareCanCan
   @project = Project.find(params[:id])  
  projectid_viewing = @project.id
end

I have the 8 hardcoded above for testing purposes. and for some reason it isn't working at the if statement, did I do that statement incorrectly? It's always allowing for can: manage

I have the Project's controller logging, so I know that the value the controller is setting to projectid_viewing is 8.

Ideas?

A: 

I'm trying to understand… Depending on the project, all user can edit it, or can edit all models? If it's the project only, I would try:

def initialize(user) 
  user ||= User.new
  can :manage, Project do |project|
    project.id == 8
  end
end
Yannis