Search code examples
ruby-on-railsactiverecordscaffoldingscaffold

Rails error when I try generate a scaffold


Sorry for my english I'm french ;)

When I try to generate a scaffold with rails g scaffold (data info) I have an error and i have never see this

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)

You know what is the solution I think the problem come of active record.

Thanks


Solution

  • You are getting the error because you have missed the model name in the generate command. Your scaffolding command should be

    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
    

    If your model name is Product, the scaffold should be like

    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