Rails 生成器 - 生成器中的多个数组参数返回“未为所需参数提供值”;
我编写了这个生成器来获取多个数组参数
class TestScaffoldGenerator < Rails::Generators::NamedBase
#template source
source_root File.expand_path("../templates", __FILE__)
#scaffold_name argument
argument :fields, :type => :array, :required => true, :desc => "required"
argument :validations, :type => :array, :required => true, :desc => "required"
argument :displays_back, :type => :array, :required => true, :desc => "required"
argument :displays_front, :type => :array, :required => true, :desc => "required"
#gem_dependancies
gem("haml")
#initial generator method
def generate_test_scaffold
template "model.rb.erb", "app/models/#{file_name}.rb"
end
#private methods do get run when generator is initiated
private
#scaffold_name to underscore gives filename
def file_name
class_name.demodelize
end
end
当我运行“rails g test_scaffold”时,我不知道如何表示数组参数的结尾和另一个数组参数的开始... 我尝试过还有更多:
'rails g test_scaffold name:string string black white'
'rails g test_scaffold name:string, string, black, white'
'rails g test_scaffold [name:string] [string] [black] [white]'
'rails g test_scaffold [name:string], [string], [black], [white]'
'rails g test_scaffold {name:string} {string} {black} {white}'
'rails g test_scaffold {name:string}, {string}, {black}, {white}'
但我总是收到错误“没有为所需参数'字段','验证','displays_back','displays_front'提供值”
我真的不知道如何表示数组......有什么建议吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
运行查看帮助
您可以像这样传递数组选项
User 是脚手架名称,可以像这样获取字段
Run to see the help
You can pass array option like this
User is the scaffold name and fields can be fetched like this