ruby-on-rails - 试图从一个类继承并在其上添加一个属性,得到一个 TypeError
问题描述
class Api::ApiResponse
attr_accessor :success, :errors
def initialize(success, errors)
@success = success
@errors = errors
end
end
class NewSessionResponse < Api::ApiResponse
attr_accessor :user
end
在我的控制器动作中,我有这个:
ar = NewSessionResponse.new(true, [])
ar.user = user
render json: ar
出于某种原因,我收到此错误:
TypeError (superclass mismatch for class NewSessionResponse)
当我在 Rails 控制台中运行此代码时,它工作正常。
顺便说一句,父类的构造函数被传递给子类?
解决方案
推荐阅读
- sql - 排序/排名 | 如果在子查询中?
- php - 试图理解 WordPress 主题 php
- android - Ionic3 Android 8.0 地理位置不起作用
- vba - Excel VBA是否可以允许对锁定的单元格进行排序?
- javascript - 以编程方式将顶点添加到 Leaflet 折线
- xcode - 从 API 转换数组时,知道何时使用 Double、String 或 Int?
- r - 使用 dplyr 根据另一列中的值添加新列
- javascript - 在 MomentJS 中将分钟转换为小时 (H:mm)
- ruby-on-rails - 无法使用 Capistrano 重置/取消设置 VERSION 环境变量
- perl - Perl 脚本 - 在终端输出中实时创建的表