good syntax for ruby scope -


i wanna know if there way of doing :

i want "invited" method user class create list of user(s) have referral_code equals self.confirmation_token

i tried lot of things , last thing know it, have syntax error ...

scope :invited, -> {|u| where("referral_code = ?", confirmation_token)} 

ofc mean want iterate on every user in database (|u|)

you write:

scope :invited, ->(token) { where("referral_code = ?", token) } 

and then: user.ivited(some_token), if need users have same referral_code , confirmation_token fields, write:

scope :invited, -> { "referral_code = confirmation_token" } 



according comment (i need users have same referral_code confirmation_token of user caller of method invited), write:

def invited   "referral_code = ?", confirmation_token end 

and then: user.last.invited


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jquery - Keeping Kendo Datepicker in min/max range -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -