how to call a active record named scope with a string

后端 未结 4 1840
梦谈多话
梦谈多话 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 14:44

    If I understand what you mean, that's what you should call it:

    @case_studies = CaseStudy.send(:some_named_scope)
    

    You can use send to call a method and pass either a symbol or a string to it.

提交回复
热议问题