Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

treat ActiveRecord::Relation as Array #917

Open
wants to merge 5 commits into from
@chrosciu

This fixes the problem with Rails 4, where ActiveRecord::Relation is no longer recognized as Array, which gives problems when defining abilities with joins - see #916

@mhenrixon

:+1: merge this quickly please is cancan dead or what?

@Loremaster

+1 for merge!

@ghost

+1 Having the exact same issue after upgrading from Rails 3.2 to 4.0. Using the cancan gem version 1.6.10.

@johncalvinyoung

About time to merge. This has been a big annoyance for me.

@ghost

+1

@nacengineer

+1 and looking forward to @ryanb coming back from sabbatical

@sproot

+1

@jcoyne

I'm hitting this too. Please merge.

@ghost

If Railscasts.com is any indication, Ryan Bates is not actively working on projects right now. If Ryan could delegate responsibility for CanCan to someone else, that would be wonderful. If someone here could take the existing pull requests and begin to maintain this gem again, I would be grateful. Until that time, I have stopped using CanCan in any new applications or in any Rails 4 application. I have moved to Pundit.

It would appear that this gem is becoming abandonware, if it isn't already :frowning:

@nacengineer

@BigNerdRanchDan @ryanb is on sabbatical due to burnout. He'll most likely be back, but it may be some time yet. Not quite abandonware yet.

@chrosciu

This change has been included in cancan successor: https://github.com/bryanrite/cancancan.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 16, 2013
  1. @madmax
Commits on Aug 13, 2013
  1. @chrosciu
  2. @chrosciu
Commits on Feb 24, 2014
  1. @madmax
  2. @madmax
This page is out of date. Refresh to see the latest.
View
14 lib/cancan/controller_resource.rb
@@ -216,14 +216,24 @@ def name
def resource_params
if @options[:class]
params_key = extract_key(@options[:class])
- return @params[params_key] if @params[params_key]
+ if params = fetch_params(params_key)
+ return params
+ end
end
resource_params_by_namespaced_name
end
def resource_params_by_namespaced_name
- @params[extract_key(namespaced_name)]
+ fetch_params extract_key(namespaced_name)
+ end
+
+ def fetch_params(key)
+ @controller.respond_to?(params_method(key), true) ? @controller.send(params_method(key)) : @params[key]
+ end
+
+ def params_method(key)
+ "#{key}_params".to_sym
end
def namespace
View
4 lib/cancan/matchers.rb
@@ -4,11 +4,11 @@
ability.can?(*args)
end
- failure_message_for_should do |ability|
+ failure_message do |ability|
"expected to be able to #{args.map(&:inspect).join(" ")}"
end
- failure_message_for_should_not do |ability|
+ failure_message_when_negated do |ability|
"expected not to be able to #{args.map(&:inspect).join(" ")}"
end
end
View
2  lib/cancan/rule.rb
@@ -111,7 +111,7 @@ def matches_conditions_hash?(subject, conditions = @conditions)
else
attribute = subject.send(name)
if value.kind_of?(Hash)
- if attribute.kind_of? Array
+ if attribute.kind_of?(Array) || attribute.kind_of?(ActiveRecord::Relation)
attribute.any? { |element| matches_conditions_hash? element, value }
else
!attribute.nil? && matches_conditions_hash?(attribute, value)
Something went wrong with that request. Please try again.