Activerecord 未显示新字段
在我对一个表进行了迁移之后,我刚刚遇到了一个问题,我在项目表中添加了owner字段,但在我请求它时它并没有出现(project) 迁移后的预期响应: 我得到: 这是我的迁移文件Activerecord 未显示新字段,activerecord,ruby-on-rails-4,Activerecord,Ruby On Rails 4,在我对一个表进行了迁移之后,我刚刚遇到了一个问题,我在项目表中添加了owner字段,但在我请求它时它并没有出现(project) 迁移后的预期响应: 我得到: 这是我的迁移文件 class AddOwnerRefToProjects < ActiveRecord::Migration def change add_reference :projects, :owner, index: true end end class AddOwnerRefToProj
class AddOwnerRefToProjects < ActiveRecord::Migration
def change
add_reference :projects, :owner, index: true
end
end
class AddOwnerRefToProjects
我的项目模型
class Project < ActiveRecord::Base
belongs_to :owner, :class_name => :User
end
class项目:用户
终止
您需要在json序列化程序中添加新属性。谢谢@AytanLeibowitz。但是很抱歉,我大约2天前才开始使用rails,json序列化程序在哪里?仅供参考,我使用的是rails 4。路径是app>serializers>project\u serializer.rbattributes:id、:name、:owner
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