Sharing Query Logic Within ActiveRecord Models
04-Oct-2019 2120
I was recently working on an application in which we had a class method / scope used to return a specific set of users. This was fine and good until we found ourselves needing to capture the same logic at the instance level. Ideally, I was hoping to be able to avoid duplicating the logic, and simultaneously keep things efficient.Users in our application can be configured to receive alerts. We have a class method on the User model used to query for all the users who can receive alerts:.
Sharing Query Logic Within ActiveRecord Models #ruby #rubydeveloper #rubyonrails #Sharing #Query #Logic #Within #ActiveRecord #Models #activerecord https://rubyonrails.ba/link/sharing-query-logic-within-activerecord-models