Project

General

Profile

« Previous | Next » 

Revision 02e4c535

Added by Daniel Lobato Garcia over 8 years ago

Fixes #11924 - Substitute .scoped by .where(nil) to force return relation

On Rails 4 .scoped is deprecated. Calling .all on the model returns the
equivalent ActiveRecord relation object on Rails 4, but on Rails 3 it
returns an Array right away.

A proper replacement we can use is where(nil) - it's ugly but it returns
the same relation in both Rails 3 and 4. There are a couple of fixes too
on models such as bookmark.rb which return where conditions ({} and
similar) instead of a relation, which is also a deprecated behavior.

We could possibly substitute these by .all after the Rails 4 migration
if they feel too 'unidiomatic'.

View differences:

app/models/concerns/authorizable.rb
if user.nil?
self.where('1=0')
elsif user.admin?
self.scoped
self.where(nil)
else
Authorizer.new(user).find_collection(resource || self, :permission => permission)
end

Also available in: Unified diff