Rails新字段未出现

时间:2014-11-12 06:00:43

标签: activerecord ruby-on-rails-4

我在完成表格迁移后遇到了问题,我已将所有者字段添加到项目表中,但是当我请求它(项目)时它不会出现。

迁移后的预期响应:

{
    projects: [
        { id: 1, name: "First proj", owner: 1 },
        { id: 2, name: "Second proj", owner: 1 }
    ]
}

我得到了:

{
    projects: [
        { id: 1, name: "First proj" },
        { id: 2, name: "Second proj" }
    ]
}

这是我的迁移文件

class AddOwnerRefToProjects < ActiveRecord::Migration
    def change
        add_reference :projects, :owner, index: true
    end
end

我的项目模型

class Project < ActiveRecord::Base
  belongs_to :owner, :class_name => :User
end

1 个答案:

答案 0 :(得分:0)

您需要在json序列化程序中添加新属性。