开发者

How do I define in the model a class method, not an instance one?

开发者 https://www.devze.com 2023-03-27 16:54 出处:网络
I want to be able to call Activity.pull_latest from a controller, but if I do class Activity < ActiveRecord::Base

I want to be able to call Activity.pull_latest from a controller, but if I do

class Activity < ActiveRecord::Base
  def pull_latest [...]

I have to call it Activity.new.pull_latest.

How do I define in the model a class method, not an instance one?开发者_运维百科


Use self:

def self.pull_latest

Then you can call Activity.pull_latest

0

精彩评论

暂无评论...
验证码 换一张
取 消