2013-07-19 44 views
0

我想爲我設計生成的用戶配置文件,這樣做,(在Rails中4):如何讓用戶在Rails中創建個人資料?

rails g scaffold Profile first_name:string last_name:string school:string user:references 

,然後這樣的:

class User < ActiveRecord::Base 
    devise :database_authenticatable, :registerable, 
     :recoverable, :rememberable, :trackable, :validatable 
    has_one :profile, :dependent => :destroy 
    accepts_nested_attributes_for :profiles 
end 

class Profile < ActiveRecord::Base 
    belongs_to :user 
    attr_accessible :first_name, :last_name, :school #where does this go in rails 4? 
end 

我想知道這是否是做這種事情的正確方法,或者我應該怎麼做?

也算是我只是通過遷移將所有這些領域直接向用戶模型...

請任何鏈接和建議,以正確地做這個將真正幫助!

回答

0

我想你應該去用戶配置文件頁面。

$ rails generate controller Users show 

,並在你的路由文件

devise_for :users 
match 'users/:id' => 'users#show', as: :user 

用戶控制器

@user = User.find(params[:id]) 
相關問題