hzamani / acts_as_relation

Multi table Inheritance for rails
http://hzamani.github.com/acts_as_relation/
MIT License
180 stars 58 forks source link

Parent.specific returns nil #29

Closed bigardone closed 11 years ago

bigardone commented 11 years ago

Hi! I'm trying to integrate acts_as_relation with Devise and CanCan, so I have the following models:

class User < ActiveRecord::Base
  rolify
  acts_as_superclass
  ....
end

class UsuarioBanco < ActiveRecord::Base
  acts_as :user, as: :usuario
  ....
end

Everything regarding acts_as_relation works fine, until I define de abilities in my bbility.rb

class Ability
  include CanCan::Ability
  def initialize(user)
    if user.es_banco?
      can [:read, :update], Banco, id: user.specific.banco_id
    end
  ....
end

My user.specific returns nil, instead of a UsuarioBanco instance... I've been using your gem in another projects, not using it with Devise models, and this worked fine. Do I have anything wrong? Thanks in advance!

jfrux commented 11 years ago

+1 getting this as well.

jfrux commented 11 years ago

Okay, I think I've determined the cause of this issue. And it's not necessarily a bug... EXAMPLE: If your columns in your superclass table are doable_id and doable_type then your superclass model should look like: acts_as_superclass(:as => :doable)