psh*_*rma 7 model ruby-on-rails devise
我已经创建了一个用户模型.我想知道如何使用我现有的用户模型配置设计.话虽这么说,我是否需要设置任何其他路由或使用我的用户方法访问atttributes.
到目前为止用户模型是
class User < ActiveRecord::Base
attr_accessible :email, :pic, :name, :username
has_many :topics
end
Run Code Online (Sandbox Code Playgroud)
我对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
Run Code Online (Sandbox Code Playgroud)
现在我打算做的就是跑
rails g migration AddDeviseColumnsToUser
Run Code Online (Sandbox Code Playgroud)
并将其添加到我的迁移文件中
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
Run Code Online (Sandbox Code Playgroud)
现在我想知道我应该如何设置路线或者我必须这样做?在我的用户模型中应该可以访问哪些属性?
更新:我已经安装了Devise并配置了它
rails generate devise:install
Run Code Online (Sandbox Code Playgroud)
只需添加devise_for :user
您的路线即可
加 attr_accessible :password, :password_confirmation
有关更多信息,请查看典型的设计模型
https://github.com/johndel/Rails-Simple-CMS/blob/master/app/models/admin.rb
(很简单)
归档时间: |
|
查看次数: |
9841 次 |
最近记录: |