Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

fixes #750 - load hooks return ActiveRecord::Model in Rails 4, use Concern #751

Merged
merged 1 commit into from

3 participants

@mculp

@ryanb -- this seems to fix the load issue when running under Rails 4. Tests are passing. But should this be approached differently, specifically, should we be adding accessible_by to ActiveRecord::Model instead of Base?

@ryanb
Owner

Awesome thanks! I haven't had a chance to look into this yet. Is it backwards compatible with Rails 3?

@mculp

Yes, I tested with a Rails 3.2.8 app. Two changes:

  • don't call extend directly, as it's deprecated
  • put the class_eval/include code in an ActiveSupport.on_load(:active_record) block -- without this, I was getting the same deprecation warning
@mikepack
Collaborator

This looks good.

Thanks @mculp!!

@ryanb ryanb merged commit f1cebde into ryanb:2.0

1 check passed

Details default The Travis build passed
@ryanb
Owner

Merged in, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 28, 2012
This page is out of date. Refresh to see the latest.
View
6 lib/cancan/model_adapters/active_record_adapter.rb
@@ -165,6 +165,8 @@ def clean_joins(joins_hash)
end
end
-ActiveRecord::Base.class_eval do
- include CanCan::ModelAdditions
+ActiveSupport.on_load(:active_record) do
+ ActiveRecord::Base.class_eval do
+ include CanCan::ModelAdditions
+ end
end
View
6 lib/cancan/model_additions.rb
@@ -2,6 +2,8 @@ module CanCan
# This module adds the accessible_by class method to a model. It is included in the model adapters.
module ModelAdditions
+ extend ActiveSupport::Concern
+
module ClassMethods
# Returns a scope which fetches only the records that the passed ability
# can perform a given action on. The action defaults to :index. This
@@ -23,9 +25,5 @@ def accessible_by(ability, action = :index)
ability.model_adapter(self, action).database_records
end
end
-
- def self.included(base)
- base.extend ClassMethods
- end
end
end
Something went wrong with that request. Please try again.