0

Devise で生成したユーザーのプロファイルを作成し、これを行いました (Rails 4 で):

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

これがこの種のことを行う正しい方法であるかどうか、または代わりに何をすべきかを知りたいですか?

また、移行を通じてこれらすべてのフィールドを User モデルに直接追加することも検討しました...

これを正しく行うためのリンクや提案は本当に役に立ちます!

4

1 に答える 1

0

ユーザー プロファイル ページを使用する必要があると思います。

$ rails generate controller Users show

そしてあなたのルートファイルで

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

ユーザーコントローラー

@user = User.find(params[:id])
于 2013-07-19T05:08:22.873 に答える