Adding parameter to a scope

前端 未结 5 1615
长情又很酷
长情又很酷 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:23

    Scope in Rails model with parameter:

    scope :scope_name, -> (parameter, ...) { where(is_deleted: parameter, ...) }  
    

    Or:

    scope :scope_name, lambda{|parameter, ...| where(is_deleted:parameter, ...)} 
    

提交回复
热议问题