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