how to call a active record named scope with a string

后端 未结 4 1431
梦谈多话
梦谈多话 2021-02-20 14:19

I\'m sure I\'m miss understanding the use of call but I thought I could do something like this.

@case_studies = CaseStudy.call(\"some_named_scope\")
         


        
4条回答
  •  鱼传尺愫
    2021-02-20 15:11

    To have an extra layer of security on top of the whitelisting BookOfGreg suggested, use public_send instead of send, it'll only work calling methods of the public interface, while send can reach even private methods.

    So:

    CaseStudy.public_send(:some_scope)

提交回复
热议问题