Adding parameter to a scope

前端 未结 5 1613
长情又很酷
长情又很酷 2021-02-03 23:38

I have a ActiveRecord query for example like this:

@result = stuff.limit(10)

where stuff is a active record query with where clauses, order by,

5条回答
  •  攒了一身酷
    2021-02-04 00:24

    Pass parameters in Rails scope

    Definition of scope

    scope :name_of_scope, ->(parameter_name) {condition whatever you want to put in scope}
    

    Calling Method

    name_of_scope(parameter_name)
    

提交回复
热议问题