Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.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_Devise - Fatal编程技术网

Ruby on rails 设计用户配置文件设置

Ruby on rails 设计用户配置文件设置,ruby-on-rails,ruby,devise,Ruby On Rails,Ruby,Devise,需要确保我的所有用户在注册(设计)到我的rails应用程序后都有一个配置文件,但不确定如何执行。有什么想法吗?创建他们的用户帐户后,只需创建他们的个人资料。该配置文件属于该帐户。该帐户有一个配置文件 class User < ActiveRecord::Base has_one :profile # choose a call back or overwrite the create after_create :add_profile private def add

需要确保我的所有用户在注册(设计)到我的rails应用程序后都有一个配置文件,但不确定如何执行。有什么想法吗?

创建他们的用户帐户后,只需创建他们的个人资料。该配置文件属于该帐户。该帐户有一个配置文件

class User < ActiveRecord::Base
  has_one :profile

  # choose a call back or overwrite the create
  after_create :add_profile

  private
  def add_profile
    self.profile = Profile.create
  end
end

class Profile < ActiveRecord::Base
  belongs_to :user
end
class用户

差不多吧。

太酷了。配置文件的视图如何?profile.html.erb?或者我应该创建脚手架配置文件?没有脚手架!:-)视图将是
app/views/profiles/show.html.erb
。我建议你做这个教程()几次(5+)来获得基本的想法。你的权利,我肯定会!那么我将如何获得配置文件模型?rails生成模型配置文件示例1:字符串示例2:字符串?是的,对于模型,使用生成器。对于控制器,生成器也可以,但是脚手架(
rails-generate-scaffold-Something
)太多了。我设法找到了我的方法。谢谢