如何在 ruby on rails 中将设计迁移添加到现有用户模型? [英] Step on how to add devise migration to existing User model in ruby on rails?
问题描述
我已经创建了一个用户模型.我想知道我应该如何使用我现有的用户模型配置设计.话虽如此,我是否需要在我的用户方法中设置任何其他路由或使属性可访问.
I have a User model created already. I am wondering how should I configure devise with my existing User model. That being said, do I need to setup any additional routes or make atttributes accessible in my user method.
到目前为止用户模型是
class User < ActiveRecord::Base
attr_accessible :email, :pic, :name, :username
has_many :topics
end
我的 CreateUsers 迁移
My migration for 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
并将其添加到我的迁移文件中
And add this to my migration file
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
现在我想知道我应该如何设置我的路线还是我必须这样做?哪些属性应该在我的用户模型中访问?
Now I am wondering how should I setup my routes or do I have to ? And what attributes should be made accessible in my User model?
更新:我已经安装了 Devise 并使用了
Update: I have already installed Devise and configured it with
rails generate devise:install
推荐答案
只需在路由中添加 devise_for :user
添加attr_accessible :password, :password_confirmation
有关更多信息,请查看典型的设计模型
and for more info take a look at a typical devise model
https://github.com/johndel/Rails-Simple-CMS/blob/master/app/models/admin.rb
(很简单)
这篇关于如何在 ruby on rails 中将设计迁移添加到现有用户模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!