Ruby code beautification, split long instructions on multiple lines

前端 未结 3 1568
悲&欢浪女
悲&欢浪女 2021-02-05 00:22

How can we write the following statement to improve readability?

Promotion.joins(:category).where([\"lft>=? and rgt<=?\", c.lft, c.rgt]).joins(:shops).wher         


        
3条回答
  •  醉梦人生
    2021-02-05 00:36

    Do it like this:

    Promotion.joins(:category).
             where(["lft>=? and rgt<=?", c.lft, c.rgt]).
             joins(:shops).
             where(:promotions_per_shops => { :shop_id => shops_id }).
             count('id', :distinct => true)
    

提交回复
热议问题