0
创建迁移到预定义属性可以具有的值时有什么办法吗?Rails用户 - 与预定义角色的角色关系?
class User < ActiveRecord::Base
belongs_to :role
end
class Role < ActiveRecord::Base
has_many :users
end
和我的迁移:
class CreateRoles < ActiveRecord::Migration
def change
create_table :roles do |t|
t.string :name # (regular, admin, etc) => how can we define these as a list?
t.timestamps
end
end
end
class AddRoleToUser < ActiveRecord::Migration
def change
add_column :users, :role_id, :integer
end
end
您可以在创建角色表后立即运行Rails代码。像夹具导入可以工作 – MrYoshiji 2014-09-02 17:10:21