我剛剛創建的屬性,如名稱,網站,生物爲我設計的用戶配置文件的模型。一切都很正常,但在Heroku上,我有100多個用戶了,所以這是相當繁瑣1.創建一個新的配置文件,2.將其分配給現有的用戶3.保存,所有在控制檯中。在Heroku
我不熟悉你可以在Heroku控制檯中做什麼,如果這甚至可能 - 但是我可以爲每個現有用戶(還沒有配置文件)批量創建100個新的配置文件。
眼下,有資料信息的任何視圖(即user.profile.name)是給我一個錯誤 - 我寧願創建一個空白的配置文件不是強迫用戶創建的界面一個新的。
的Rails 3.2.12
user.rb
class User < ActiveRecord::Base
after_create :build_profile
attr_accessible :email, :password, :password_confirmation, :remember_me, :name, :role, :profile_attributes
has_one :profile, dependent: :destroy
accepts_nested_attributes_for :profile
profile.rb
class Profile < ActiveRecord::Base
attr_accessible :bio, :name, :website, :user_id
belongs_to :user
您可能需要使用user.save取決於如何建立您的build_profile。 – Mkou 2014-08-27 21:01:23
我確實包括user.save - 沒有意識到遷移可能會被用於此,而使得這麼多的意義。謝謝!! – 2014-08-27 23:40:25
謝謝!我最終寫了一個耙子任務。我會在一個單獨的答案中添加它。 – 2014-12-25 20:44:26