Home Rails error when I try generate a scaffold
Reply: 2

Rails error when I try generate a scaffold

M.Mazet
1#
M.Mazet Published in 2018-01-12 19:03:52Z

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

Anees Muhammed
2#
Anees Muhammed Reply to 2018-01-12 19:12:45Z

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
Nimish Gupta
3#
Nimish Gupta Reply to 2018-01-12 19:18:45Z

Your syntax for generating a scaffold is incorrect.

A scaffold in Rails is a full set of model, database migration for that model, controller to manipulate it, views to view and manipulate the data, and a test suite for each of the above.

You are missing the model_name here

Syntax is rails g scaffold model_name data_hash

For 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
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.304929 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO