问题描述
我已经建立了一个用户模型。我想知道如何配置我的现有用户模型的设计。话虽如此,我需要设置任何其他路由或使用我的用户方法访问atttributes。目前为止,用户模型是
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
在路线中添加 devise_for:user
添加 attr_accessible :密码,密码确认
而且有关更多信息,请查看典型的设计模型
(很简单)
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.
So far user model is
class User < ActiveRecord::Base
attr_accessible :email, :pic, :name, :username
has_many :topics
end
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
Now what I plan to do is run
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?
Update: I have already installed Devise and configured it with
rails generate devise:install
Just add devise_for :user
in your routes
Add 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
(Pretty simple)
这篇关于如何在rails上的ruby中添加设计迁移到现有用户模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!