現象
モデルでメソッドを定義して、Controllerで呼び出すと以下のエラー。
NoMethodError (undefined method `hello' for Home:Class
myrails/app/controllers/homes_controller.rb
class Home < ApplicationRecord
  def hello
    p 'hello! class method'
  end
end
myrails/app/models/home.rb
class HomesController < ApplicationController
  def index
    Home.hello
  end
end
原因
インスタンスメソッドで定義したものをクラスメソッドとして呼び出しているため。
対応
クラスメソッドとインスタンスメソッド、それぞれの定義と呼び出し方が必要。
myrails/app/controllers/homes_controller.rb
class Home < ApplicationRecord
  # クラスメソッドの場合
  def self.hello
    p 'hello! class method'
  end
  # インスタンスメソッドの場合
  def instance_hello
    p 'hello! instance method'
  end
end
myrails/app/models/home.rb
class HomesController < ApplicationController
  def index
    # クラスメソッドの場合
    Home.hello
    # インスタンスメソッドの場合
    home = Home.new
    home.instance_hello
  end
end
出力結果
Started GET "/homes" for 127.0.0.1 at 2022-09-01 23:47:19 +0900
Processing by HomesController#index as */*
"hello! class method"
"hello! instance method"
Completed 204 No Content in 0ms (Allocations: 67)