Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails RubyonRails+;designe:如何使用design-rake db:migrate创建自定义用户表?_Ruby On Rails_Devise_Ruby On Rails 3.1 - Fatal编程技术网

Ruby on rails RubyonRails+;designe:如何使用design-rake db:migrate创建自定义用户表?

Ruby on rails RubyonRails+;designe:如何使用design-rake db:migrate创建自定义用户表?,ruby-on-rails,devise,ruby-on-rails-3.1,Ruby On Rails,Devise,Ruby On Rails 3.1,rails生成设计用户我得到了这个=> class DeviseCreateUsers < ActiveRecord::Migration def self.up create_table(:users) do |t| t.database_authenticatable :null => false t.recoverable t.rememberable t.trackable # t.encryptabl

rails生成设计用户我得到了这个=>

class DeviseCreateUsers < ActiveRecord::Migration
  def self.up
    create_table(:users) do |t|
      t.database_authenticatable :null => false
      t.recoverable
      t.rememberable
      t.trackable

      # t.encryptable
      # t.confirmable
      # t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both
      # t.token_authenticatable


      t.timestamps
    end

    add_index :users, :email,                :unique => true
    add_index :users, :reset_password_token, :unique => true
    # add_index :users, :confirmation_token,   :unique => true
    # add_index :users, :unlock_token,         :unique => true
    # add_index :users, :authentication_token, :unique => true
  end

  def self.down
    drop_table :users
  end
end

您可以执行迁移,将一些字段添加到用户表中。 例如:

rails g add_fields_to_users username:string # as well as other fields you need
然后,为了向表中添加列,请运行:

rake db:migrate
Desive已经生成了一些您需要的列,如:电子邮件、密码、创建位置、更新位置

要在用户模型中添加角色,您应该观看cancan屏幕广播:并阅读以查看一些更新

编辑:

如果要手动添加字段,可以在运行迁移之前在self.up方法中添加字段:

def self.up
  create_table(:users) do |t|

    #...

    t.rememberable
    t.trackable

    t.string :username
    #... your other attributes here

  end

我不想从命令行或终端添加列,如何编辑该文件以包含这些列?您可以发布您编辑的DesiveCreateUsers文件吗?不可以:)您必须查看Desive文档才能了解哪些模块适合您。(您还可以阅读《rails 3 in action》一书中的内容,其中解释了每个Desive模块)使用Desive_Authenticatable,您已经设置了密码和电子邮件字段,因此您只需添加用户名和其他字段。您还可以通过db浏览器查看Desive生成的字段。这可能是有用的设计文件有:哪里是密码和电子邮件字段设置?如何确保设置了电子邮件和密码。我在迁移文件中没有看到这些电子邮件和密码字段。这显然是我所知的更高的内容,但您可以查看这些负责设置电子邮件和密码的文件:和
rake db:migrate
def self.up
  create_table(:users) do |t|

    #...

    t.rememberable
    t.trackable

    t.string :username
    #... your other attributes here

  end