Call a model method in a Controller

前端 未结 3 1294
一向
一向 2021-01-31 02:34

I\'m have some difficulties here, I am unable to successfully call a method which belongs to a ProjectPage model in the ProjectPage contro

3条回答
  •  时光说笑
    2021-01-31 03:21

    Declare like this in model

    def self.form_search(searches)
      searches = searches.where('amount > ?', params[:price_min]) if check_params(params[:price_min])
      @project_pages = ProjectPage.where(:project_id => searches.pluck(:'projects.id'))
    end
    

    and call from controller

    @project_pages = ProjectPage.form_search(params)
    

提交回复
热议问题