Формат, который вы используете, не совсем корректен. Посмотрите на rails g model --help
для объяснения того, как использовать модификаторы. Вот модифицированная версия того, что вы ищете, хотя она не обрабатывает все интересующие вас случаи:
rails generate resource Employee first_name:string{40} last_name:string{40} birth_date:date sex:boolean salary:integer supervisor_id:integer:index branch_id:integer:index
Это генерирует следующее:
class CreateEmployees < ActiveRecord::Migration
def change
create_table :employees do |t|
t.string :first_name, limit: 40
t.string :last_name, limit: 40
t.date :birth_date
t.boolean :sex
t.integer :salary
t.integer :supervisor_id
t.integer :branch_id
t.timestamps null: false
end
add_index :employees, :supervisor_id
add_index :employees, :branch_id
end
end
Вам нужно будет вручную добавить null: false
к тем записям, где вы хотите.
Но, если Branch и Supervisor также являются объектами AR, вы можете сделать следующее:
rails generate resource Employee first_name:string{40} last_name:string{40} birth_date:date sex:boolean salary:integer supervisor:references branch:references
, который генерирует следующее:
class CreateEmployees < ActiveRecord::Migration
def change
create_table :employees do |t|
t.string :first_name, limit: 40
t.string :last_name, limit: 40
t.date :birth_date
t.boolean :sex
t.integer :salary
t.references :supervisor, index: true, foreign_key: true
t.references :branch, index: true, foreign_key: true
t.timestamps null: false
end
end
end
, что может быть больше, чем вы ищете