我正在使用Rails 4和Devise.我试图在我的应用程序上发布的状态中显示用户的名字.我已经完成了我能想到的一切(添加用户模型后迁移的数据库)并且数据库仍然没有保存我的标题中列出的三个新字段,Devise保存了它附带的东西(电子邮件+密码)而不是新字段.
这是我的user.rb:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible attributes for your model
attr_accessible :role_ids, :as => :admin
attr_accessible :email, :password, :password_confirmation, :remember_me,
:first_name, :last_name, :profile_name
end
Run Code Online (Sandbox Code Playgroud)
我的数据库迁移:
class DeviseCreateUsers < ActiveRecord::Migration
def change
create_table(:users) do |t|
t.string: :first_name;
t.string: :last_name;
t.string: :profile_name;
## Database authenticatable
t.string :email, null: false, default: ""
t.string :encrypted_password, null: false, default: "" …Run Code Online (Sandbox Code Playgroud)