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

rdbms - what exactly the undo information lives in oracle? -

bash - How do you programmatically add a bats test? -

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