我尝试生成脚手架时出现Rails错误

时间:2018-01-12 19:03:52

标签: ruby-on-rails activerecord scaffolding scaffold

对不起我的英语我是法国人;)

当我尝试使用rails g scaffold (data info)生成脚手架时,我有一个错误,我从未见过这个

rails g scaffold title:string language:string engine:string little_description:string description:text on_production:boolean game_type:string platform:string dimension:string
      invoke  active_record
Traceback (most recent call last):
    34: from bin/rails:4:in '<main>'
    33: from bin/rails:4:in 'require'
    32: from /usr/local/lib/ruby/gems/2.5.0/gems/railties-5.1.4/lib/rails/commands.rb:16:in '<top (required)>'
    31: from /usr/local/lib/ruby/gems/2.5.0/gems/railties-5.1.4/lib/rails/command.rb:44:in 'invoke'
    30: from /usr/local/lib/ruby/gems/2.5.0/gems/railties-5.1.4/lib/rails/command/base.rb:63:in 'perform'
    29: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor.rb:387:in 'dispatch'
    28: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in 'invoke_command'
    27: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor/command.rb:27:in 'run'
    26: from /usr/local/lib/ruby/gems/2.5.0/gems/railties-5.1.4/lib/rails/commands/generate/generate_command.rb:24:in 'perform'
    25: from /usr/local/lib/ruby/gems/2.5.0/gems/railties-5.1.4/lib/rails/generators.rb:269:in 'invoke'
    24: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor/base.rb:466:in 'start'
    23: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor/group.rb:232:in 'dispatch'
    22: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor/invocation.rb:133:in 'invoke_all'
    21: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor/invocation.rb:133:in 'map'
    20: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor/invocation.rb:133:in 'each'
    19: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor/invocation.rb:133:in 'block in invoke_all'
    18: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in 'invoke_command'
    17: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor/command.rb:27:in 'run'
    16: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor/group.rb:133:in '_invoke_from_option_orm'
    15: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor/group.rb:266:in '_invoke_for_class_method'
    14: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor/shell.rb:68:in 'with_padding'
    13: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor/group.rb:277:in 'block in _invoke_for_class_method'
    12: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor/invocation.rb:115:in 'invoke'
    11: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor/group.rb:232:in 'dispatch'
    10: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor/invocation.rb:133:in 'invoke_all'
     9: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor/invocation.rb:133:in 'map'
     8: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor/invocation.rb:133:in 'each'
     7: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor/invocation.rb:133:in 'block in invoke_all'
     6: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in 'invoke_command'
     5: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor/command.rb:27:in 'run'
     4: from /usr/local/lib/ruby/gems/2.5.0/gems/railties-5.1.4/lib/rails/generators/named_base.rb:236:in 'block in check_class_collision'
     3: from /usr/local/lib/ruby/gems/2.5.0/gems/railties-5.1.4/lib/rails/generators/base.rb:249:in 'class_collisions'
     2: from /usr/local/lib/ruby/gems/2.5.0/gems/railties-5.1.4/lib/rails/generators/base.rb:249:in 'each'
     1: from /usr/local/lib/ruby/gems/2.5.0/gems/railties-5.1.4/lib/rails/generators/base.rb:258:in 'block in class_collisions'
/usr/local/lib/ruby/gems/2.5.0/gems/railties-5.1.4/lib/rails/generators/base.rb:258:in 'const_defined?': wrong constant name Title:string (NameError)

你知道解决方案是什么 我认为问题来自积极的记录。

由于

2 个答案:

答案 0 :(得分:0)

您收到错误是因为您错过了generate命令中的模型名称。你的脚手架命令应该是

rails g scaffold <ModelName> title:string language:string engine:string little_description:string description:text on_production:boolean game_type:string platform:string dimension:string

如果您的型号名称为Product,则脚手架应该类似于

rails g scaffold Product title:string language:string engine:string little_description:string description:text on_production:boolean game_type:string platform:string dimension:string

答案 1 :(得分:0)

您生成脚手架的语法不正确。

Rails中的脚手架是一整套模型,该模型的数据库迁移,操作它的控制器,查看和操作数据的视图,以及上述每个模型的测试套件。

您在这里缺少model_name

语法为 rails g scaffold model_name data_hash

对于Ex

rails g scaffold Product title:string language:string engine:string little_description:string description:text on_production:boolean game_type:string platform:string dimension:string