我正试图使用以下方法创建一个Rails 5 api应用程序 http:/alessiofanelli.comlogbuilding-a-rails-5-andember-js-app。.
我得到的
找不到api_controller.rb。
在执行如下脚手架命令时出现错误。
$ rails g scaffold team name:string city:string championships:integer
在进程32480中通过Spring预加载器运行 invoke active_record identical dbmigrate20160204101609_create_teams.rb identical appmodelsteam.rb invoke test_unit identical testmodelsteam_test.rb identical testfixturesteams.yml invoke resource_route route resources :teams identical appserializersteam_serializer.rb invoke scaffold_controller 在你的任何源路径中都找不到 "api_controller.rb"。您当前的源代码路径是: homekpatil.gemrubygemsactive_model_serializers-0.9.4libactive_modelserializergeneratorsserializertemplates。
终端显示以下信息
$ rails s
=> Booting Puma
=> Rails 5.0.0.beta2 application starting in development on http://localhost:3000
=> Run rails server -h for more startup options
=> Ctrl-C to shutdown server
Puma 2.16.0 starting...
Min threads: 0, max threads: 16
Environment: development
Listening on tcp://localhost:3000 Started POST "/teams" for 127.0.0.1 at 2016-02-04 16:25:06 +0530 ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
ActionController::RoutingError (uninitialized constant TeamsController):
activesupport (5.0.0.beta2) lib/active_support/inflector/methods.rb:259:in const_get' activesupport (5.0.0.beta2) lib/active_support/inflector/methods.rb:259:inblock in constantize'
activesupport (5.0.0.beta2) lib/active_support/inflector/methods.rb:257:in each' activesupport (5.0.0.beta2) lib/active_support/inflector/methods.rb:257:ininject'
activesupport (5.0.0.beta2) lib/active_support/inflector/methods.rb:257:in constantize' actionpack (5.0.0.beta2) lib/action_dispatch/http/request.rb:93:incontroller_class'
actionpack (5.0.0.beta2) lib/action_dispatch/routing/route_set.rb:44:in controller' actionpack (5.0.0.beta2) lib/action_dispatch/routing
我遇到了和你一样的问题。我修复了这个问题,安装。
gem 'active_model_serializers', '~> 0.10.0.rc1' 。
之前,我有0.9.4版本的这个宝石。现在脚手架生成器工作正常。
谢谢
有同样的问题&发现如果你安装了活动管理员,也会发生这种情况。
解决办法是在您的 config/application.rb
:
config.app_generators.scaffold_controller = :scaffold_controller