Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Mongoid: instances loaded with .only() never satisfy can? method #793

Open
sbauch opened this Issue Dec 17, 2012 · 2 comments

Comments

Projects
None yet
3 participants

sbauch commented Dec 17, 2012

Using rails 3.2.6, CanCan 1.6.8, and mongoid 3.05.

I have a Products collection where each Product document can be quite large.

Each user document has an array of Product IDs that the user "owns" under the :products field, and the user can manage those products.

Defined in ability.rb as

can :manage, Product, :_id.in => user.products 

I want to load all of my products in an index action, and use the can? method in the view to either render a link to the show action of the product if the current_user owns it or simply the name of the product if the user does not.

I want to use the mongo .only() query modifier to return only those fields that are immediately necessary. I thought that including the id would allow the can? method to work properly, but it does not.

def index
  @products = Product.all #can? in view satisfied for proper products
  @products = Product.all.only(:name, :_id, :price)  # can? never satisfied
end

Does CanCan require I load the whole mongo document? I'd be happy to post more of my application code, but since it all works flawlessly without .only() I have to believe this is an isolated issue.

@sbauch Is this still an issue?

xhoy commented Apr 10, 2014

Dear submitter, Since cancan/raynB hasn't been active for more than 6 months and no body else then ryam himself has commit permissions the cancan project is on a stand still.
Since cancan has several issues including missing support for rails 4 cancan is moving forward to cancancan. More details on: #994

If your feel that your pull request or bug is still applicable (and hasn't been merged in to cancan) it would be really appreciated if you would resubmit it to cancancan (https://github.com/cancancommunity/cancancan)

We hope to see you on the other side!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment