命令行哈希输入

Command Line hash input

我有一个发电机 class 我可以 运行 像这样:

rails g shopping_template --attributes=email:hello

它将电子邮件识别为输入。但是当我想添加几个属性时它不起作用,它只识别电子邮件:

rails g shopping_template --attributes=email:hello,name:hans,house:big

我是否必须更改 --attributes=email:hello,name:hans,house:big 以便将其正确识别为散列?

这是来自 class 的代码:

class_option :attributes,
             type: :hash,
             default: {}

勾选Thor document。这是传递散列的正确方法:

--option=name:string age:integer

因此对于您的示例,它将是:

--attributes=email:hello name:hans house:big