Ruby code beautification, split long instructions on multiple lines

前端 未结 3 1573
悲&欢浪女
悲&欢浪女 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:30

    Also possible to do

    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)
    

提交回复
热议问题