我已经创建了一个用户模型。我想知道如何使用我现有的用户模型配置设计。话虽这么说,我是否需要设置任何其他路由或使用我的用户方法访问atttributes。
到目前为止用户模型是
class User < ActiveRecord::Base
attr_accessible :email, :pic, :name, :username
has_many :topics
end
我对CreateUsers的迁移
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :name
t.string :email
t.string :username
t.string :pic
t.timestamps
end
end
end
现在我打算做的是运行
rails g migration AddDeviseColumnsToUser
并将其添加到我的迁移文件
class AddDeviseColumnsToUser < ActiveRecord::Migration
def change
change_table :users do |t|
t.string :encrypted_password, :null => false, :default => '', :limit => 128
t.confirmable
t.recoverable
t.rememberable
t.trackable
t.token_authenticatable
t.timestamps
end
end
end
现在我想知道我应该如何设置路线或者我必须这样做?在我的用户模型中应该可以访问哪些属性?
更新:我已经安装了Devise并使用
对其进行了配置rails generate devise:install
答案 0 :(得分:9)
只需在路线中添加devise_for :user
添加attr_accessible :password, :password_confirmation
有关更多信息,请查看典型的设计模型
https://github.com/johndel/Rails-Simple-CMS/blob/master/app/models/admin.rb
(非常简单)
答案 1 :(得分:4)
您只需运行:
rails generate devise User
将设计添加到用户模型。