Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何在设计模型和我制作的模型之间建立关联?_Ruby On Rails_Ruby_Web_Devise - Fatal编程技术网

Ruby on rails 如何在设计模型和我制作的模型之间建立关联?

Ruby on rails 如何在设计模型和我制作的模型之间建立关联?,ruby-on-rails,ruby,web,devise,Ruby On Rails,Ruby,Web,Devise,您如何使用用户(设计哪个存储电子邮件和密码)属于个人资料,并且个人资料只有一个用户?当我查找数据库配置文件时,int仍然是nil-hmmm。。。不知道我哪里做错了 class User < ActiveRecord::Base # Include default devise modules. Others available are: # :token_authenticatable, :confirmable, # :lockable, :timeoutable and :omn

您如何使用用户(设计哪个存储电子邮件和密码)属于个人资料,并且个人资料只有一个用户?当我查找数据库配置文件时,int仍然是nil-hmmm。。。不知道我哪里做错了

class User < ActiveRecord::Base
 # Include default devise modules. Others available are:
 # :token_authenticatable, :confirmable,
 # :lockable, :timeoutable and :omniauthable
    devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable

 # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :password, :password_confirmation, :remember_me, :profile_id
 # attr_accessible :title, :body

  belongs_to :profile
end


class Profile < ActiveRecord::Base
 attr_accessible :dob, :firstName, :lastName, :school_id, :schYear, :user_attributes


 belongs_to :school
 has_one :user
 accepts_nested_attributes_for :user

end
class用户

我知道通常我应该这样做。创建(……)但是如果我用一个装置来做,我不确定在哪里做这件事?您是否运行了rake db:migrate


此外,检查您的模式也会有所帮助。

将设备
用户
配置文件
模型关联的常见做法是将配置文件作为用户的子项:

# app/models/user.rb
class User < ActiveRecord::Base
    has_one :profile
end

# app/models/profile.rb
class Profile < ActiveRecord::Base
    belongs_to :user
end

哦,糟糕,那是个打字错误。。。这只是“学校”,但主要的问题仍然存在,我不确定如何将这两个模型关联到一个has_-one和bells_-to关系中看起来你设置正确,你尝试过运行另一个迁移吗?是的,我尝试过。它什么也没做。。。我只是想知道,既然用户是由gem文件“designe”创建的,那么我如何访问它的控制器文件,以便我可以配置文件。create(……User:…)如果您想自定义designe控制器,您必须创建一个从designe继承的新控制器:。否则,用户将通过视图中已填写的设计注册表格创建。您可以自定义这些视图,但必须首先使用rails生成设备导入它们:viewsDid您找到解决方案了吗?
# app/models/user.rb
after_create :create_profile

def create_profile
    profile = Profile.create
    self.profile = profile
    self.save
end