0
次のように私はApplicationRecord
モデルを持っている:Railsの5モデルが親のメソッドを継承していない
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
def hello_world
return "helllloo"
end
end
をし、次のように私はInstance
モデルを持っている:
class Instance < ApplicationRecord
end
それから私は、コントローラが実行しようとしていますhello_world
ですが、hello_world
メソッドが利用できないという次のエラーが発生しています。
コントローラ
class InstancesController < ApplicationController
before_action :set_instance, only: [:show, :update, :destroy]
# GET /instances
def index
@instances = Instance.all
return render(:json => {:instances => @instances, :hi_message => Instance.hello_world})
end
end
エラー
{
"status": 500,
"error": "Internal Server Error",
"exception": "#<NoMethodError: undefined method `hello_world' for #<Class:0x00000009b3d4a0>>",
"traces": {
"Application Trace": [
{
"id": 1,
"trace": "app/controllers/instances_controller.rb:7:in `index'"
}
],.....
それがメソッドを継承していない理由を任意のアイデア?
**注:**私はAPIモードでアプリを実行しています。ここで言及する