[英]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 (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)
You know what is the solution I think the problem come of active record. 您知道解决方案是什么,我认为问题来自主动记录。
Thanks 谢谢
You are getting the error because you have missed the model name in the generate command. 之所以收到此错误,是因为您在generate命令中错过了型号名称。 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 如果您的型号名称为
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
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. Rails中的脚手架是完整的模型集,该模型的数据库迁移,用于操纵模型的控制器,用于查看和操纵数据的视图以及用于上述每个模型的测试套件。
You are missing the model_name here 您在这里缺少model_name
Syntax is rails g scaffold model_name data_hash
语法是
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.