Call a model method in a Controller

前端 未结 3 1304
一向
一向 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:30

    To complete davidb's answer, two things you're doing wrong are:

    1) you're calling a model's function from a controller, when the model function is only defined in the model itself. So you do need to call

    Project.form_search
    

    and define the function with

    def self.form_search
    

    2) you're calling params from the model. In the MVC architecture, the model doesn't know anything about the request, so params is not defined there. Instead, you'll need to pass the variable to your function like you're already doing...

提交回复
热议问题