繼格爾登的答案,你需要真正有profile
重定向到:
模式
#app/models/profile.rb
Class Profile < ActiveRecord::Base
belongs_to :user
end
#app/models/user.rb
Class User < ActiveRecord::Base
has_one :profile
before_create :build_profile #creates profile at user registration
end
模式
profiles
id | user_id | name | birthday | other | info | created_at | updated_at
條
路線
#config/routes.rb
resources :profiles, only: [:edit]
控制器
#app/controllers/profiles_controller.rb
def edit
@profile = Profile.find_by user_id: current_user.id
@attributes = Profile.attribute_names - %w(id user_id created_at updated_at)
end
查看
#app/views/profiles/edit.html.erb
<%= form_for @profile do |f| %>
<% @attributes.each do |attr| %>
<%= f.text_field attr.to_sym %>
<% end %>
<% end %>
然後,您需要聘請after_sign_in_path
東西格爾登發佈
更新
這裏是遷移你會使用:
# db/migrate/[[timestamp]]_create_profiles.rb
class CreateProfiles < ActiveRecord::Migration[5.0]
def change
create_table :profiles do |t|
t.references :user
# columns here
t.timestamps
end
end
end
真棒,我實際上已經創建了一個user_profiles腳手架來照顧大部分。我希望我可以讓你和Kirti的答案都得到滿足,但我還沒有代表。該網站正在將用戶重定向到他們自己的個人資料頁面,現在我需要弄清楚如何將他們自己的個人信息放在該頁面上。 – user3254679
感謝您的反饋 - 希望它有幫助!您可以使用我製作的代碼來顯示您需要的數據! –
你如何將該模式添加到數據庫? –