I have a instance variable in my controller that I'm trying to convert into a scope for my model.
Instance variable: products
@products_with_user_differences = Product.where{|p| p.last_user != p.user.username && p.asset_type.name == "Computer" unless p.user.nil? or p.allow_multi_users == true}
Explanation:
This shows all Products that have a last_user value different from the user.username with a type of "Computer". It also excludes any Product that user_id: is nil or have allow_multi_users attribute set to TRUE.
I've tried the following with zero luck: Products.rb
scope :with_user_differences, -> { where(last_user != user.username && asset_type.name == "Computer" unless user.nil? or allow_multi_users == true)}
It doesn't seem to recognize associations or allow "!=" in the scope.
Any ideas or pointers?