Ruby on rails 命名错误:未定义的方法“arel#u表';至于;用户";:一串
轨道4.2 g.user\u策展人Ruby on rails 命名错误:未定义的方法“arel#u表';至于;用户";:一串,ruby-on-rails,ruby,associations,Ruby On Rails,Ruby,Associations,轨道4.2 g.user\u策展人 NoMethodError: undefined method `arel_table' for "User":String 我的桌子: create_table "groups", force: :cascade do |t| t.string "name", limit: 255, default: "", null: false t.integer "user_curator_id", limit: 4
NoMethodError: undefined method `arel_table' for "User":String
我的桌子:
create_table "groups", force: :cascade do |t|
t.string "name", limit: 255, default: "", null: false
t.integer "user_curator_id", limit: 4
t.integer "user_leader_id", limit: 4
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "users", force: :cascade do |t|
t.string "email", limit: 255, default: "", null: false
t.string "encrypted_password", limit: 255, default: "", null: false
t.datetime "created_at"
t.datetime "updated_at"
t.integer "access_level", limit: 4, default: 0
t.string "first_name", limit: 255
t.string "last_name", limit: 255
t.string "middle_name", limit: 255
end
我的模型:
class User < ActiveRecord::Base
has_one :user_curator, :class_name => 'Group'
end
class Group < ActiveRecord::Base
belongs_to :user_curator, :class => 'User', foreign_key: "user_curator_id"
end
class用户“组”
结束
类组“用户”,外键:“用户管理员id”
结束
帮助正确设置表的关联。在团队中担任策展人和领导者(表用户)类组
这将起作用我在您的用户表模式中看不到
user\u curator\u id
您的问题不清楚,请解释要设置为关联的内容组必须是与user表的链接,字段为user\u curator\u id,user\u leader\u id,has\u one这是一个数据库模式
class Group < ActiveRecord::Base
belongs_to :curator, class_name: 'User', foreign_key: 'user_curator_id'
end
class User < ActiveRecord::Base
has_one :group, foreign_key: 'user_curator_id'
end