Apply ability to group_method in grouped_collection_select #661

Open
jmaniv opened this Issue Jun 23, 2012 · 3 comments

Comments

Projects
None yet
3 participants
@jmaniv

jmaniv commented Jun 23, 2012

For example I have the following models

class Part < ActiveRecord::Base
has_and_belongs_to_many :assemblies
end

class Assembly < ActiveRecord::Base
  has_and_belongs_to_many :parts
end

class Engine < ActiveRecord::Base
belongs_to :assembly
end

I am trying to add assembly_id into engine table;

f.grouped_collection_select(:assembly_id, @parts, :assemblies, :name, :id, :name)

I am able to apply ability to 'Part' model; but, I want to restrict certain assembly records while fetching through grouped_collection_select.

I am unable to apply ability on 'grouped_method' [:assemblies]

Found that Rails automatically fetches the assemblies through @Parts

@andhapp

This comment has been minimized.

Show comment Hide comment
@andhapp

andhapp Jul 4, 2012

Collaborator

@jmaniv: Can you please post your ability file? Thanks.

Collaborator

andhapp commented Jul 4, 2012

@jmaniv: Can you please post your ability file? Thanks.

@jmaniv

This comment has been minimized.

Show comment Hide comment
@jmaniv

jmaniv Jul 4, 2012

can :manage, Part, :customer_id => current_user.customer_id
can :read, Assembly, :user_id => current_user.id, :active => true

Here I can able to apply current ability to part model like
@parts = Part.accessible_by(current_ability).order(:name)

While loading parts, inactive(:active => false) and other user's assemblies are loaded by rails. But, as per ability only active(:active => true) and current user's records should be loaded.

jmaniv commented Jul 4, 2012

can :manage, Part, :customer_id => current_user.customer_id
can :read, Assembly, :user_id => current_user.id, :active => true

Here I can able to apply current ability to part model like
@parts = Part.accessible_by(current_ability).order(:name)

While loading parts, inactive(:active => false) and other user's assemblies are loaded by rails. But, as per ability only active(:active => true) and current user's records should be loaded.

@xhoy

This comment has been minimized.

Show comment Hide comment
@xhoy

xhoy Jul 1, 2014

Thanks for your submission! The ryanb/cancan repository has been inactive since Sep 06, 2013.
Since only Ryan himself has commit permissions, the CanCan project is on a standstill.

CanCan has many open issues, including missing support for Rails 4. To keep CanCan alive, an active fork exists at cancancommunity/cancancan. The new gem is cancancan. More info is available at #994.

If your pull request or issue is still applicable, it would be really appreciated if you resubmit it to CanCanCan.

We hope to see you on the other side!

xhoy commented Jul 1, 2014

Thanks for your submission! The ryanb/cancan repository has been inactive since Sep 06, 2013.
Since only Ryan himself has commit permissions, the CanCan project is on a standstill.

CanCan has many open issues, including missing support for Rails 4. To keep CanCan alive, an active fork exists at cancancommunity/cancancan. The new gem is cancancan. More info is available at #994.

If your pull request or issue is still applicable, it would be really appreciated if you resubmit it to 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