Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/66.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 在Rails模板中向脚本/生成命令添加默认值和索引?_Ruby On Rails_Templates_Migration - Fatal编程技术网

Ruby on rails 在Rails模板中向脚本/生成命令添加默认值和索引?

Ruby on rails 在Rails模板中向脚本/生成命令添加默认值和索引?,ruby-on-rails,templates,migration,Ruby On Rails,Templates,Migration,我正在尝试设置一个Rails模板,允许全面设置特定的Rails应用程序。使用Pratik Naik的overview(),我可以设置一些脚手架和模型,其中一行看起来像这样 generate("scaffold", "post", "title:string", "body:string") 我现在正在尝试添加延迟作业,它通常有一个如下所示的迁移文件: create_table :delayed_jobs, :force => true do |table| table.integer

我正在尝试设置一个Rails模板,允许全面设置特定的Rails应用程序。使用Pratik Naik的overview(),我可以设置一些脚手架和模型,其中一行看起来像这样

generate("scaffold", "post", "title:string", "body:string")
我现在正在尝试添加延迟作业,它通常有一个如下所示的迁移文件:

create_table :delayed_jobs, :force => true do |table|
  table.integer  :priority, :default => 0      # Allows some jobs to jump to the front of the queue
  table.integer  :attempts, :default => 0      # Provides for retries, but still fail eventually.
  table.text     :handler                      # YAML-encoded string of the object that will do work
  table.text     :last_error                   # reason for last failure (See Note below)
  table.datetime :run_at                       # When to run. Could be Time.now for immediately, or sometime in the future.
  table.datetime :locked_at                    # Set when a client is working on this object
  table.datetime :failed_at                    # Set when all retries have failed (actually, by default, the record is deleted instead)
  table.string   :locked_by                    # Who is working on this object (if locked)
  table.timestamps
end
generate("migration", "createDelayedJobs", "priority:integer", "attempts:integer", "handler:text", "last_error:text", "run_at:datetime", "locked_at:datetime", "failed_at:datetime", "locked_by:string")
因此,我试图使用Rails模板,将:default=>0添加到主模板文件中。我知道模板命令的其余部分应该如下所示:

create_table :delayed_jobs, :force => true do |table|
  table.integer  :priority, :default => 0      # Allows some jobs to jump to the front of the queue
  table.integer  :attempts, :default => 0      # Provides for retries, but still fail eventually.
  table.text     :handler                      # YAML-encoded string of the object that will do work
  table.text     :last_error                   # reason for last failure (See Note below)
  table.datetime :run_at                       # When to run. Could be Time.now for immediately, or sometime in the future.
  table.datetime :locked_at                    # Set when a client is working on this object
  table.datetime :failed_at                    # Set when all retries have failed (actually, by default, the record is deleted instead)
  table.string   :locked_by                    # Who is working on this object (if locked)
  table.timestamps
end
generate("migration", "createDelayedJobs", "priority:integer", "attempts:integer", "handler:text", "last_error:text", "run_at:datetime", "locked_at:datetime", "failed_at:datetime", "locked_by:string")
我应该把:默认值放在哪里(或者说,应该添加什么语法)?如果我想添加索引,最好的方法是什么?

我认为不可能将额外的信息传递到模板生成调用中。模板系统不是特别广泛。我可能错了,当然。。。另一个选项可能是只将您想要的行注入到生成的迁移文件中。查看helper.rb文件中的方法,以及mobile.rb文件中的使用示例