2

我正在尝试使用http://alessiofanelli.com/blog/building-a-rails-5-and-ember-js-app创建一个 Rails 5 api 应用程序。

我明白了

找不到 api_controller.rb

执行脚手架命令时出错,如下所示。

$ rails g scaffold team name:string city:string championships:integer 

在进程 32480 中通过 Spring 预加载器运行调用 active_record 相同 db/migrate/20160204101609_create_teams.rb 相同 app/models/team.rb 调用 test_unit 相同 test/models/team_test.rb 相同 test/fixtures/teams.yml 调用 resource_route 路由资源:teams 相同app/serializers/team_serializer.rb 调用 scaffold_controller 在您的任何源路径中都找不到“api_controller.rb”。您当前的源路径是:/home/kpatil/.gem/ruby/gems/active_model_serializers-0.9.4/lib/active_model/serializer/generators/serializer/templates

在终端中显示以下消息

$ 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
4

2 回答 2

10

我和你有同样的问题。我解决了这个问题安装:

gem 'active_model_serializers', '~> 0.10.0.rc1'

之前,我有这个 gem 的 0.9.4 版本。现在脚手架生成器工作正常。

问候!

于 2016-02-06T10:58:46.097 回答
1

有同样的问题并发现如果您安装了活动管理员也会发生这种情况。

然后解决方案是添加您的config/application.rb

config.app_generators.scaffold_controller = :scaffold_controller
于 2020-05-22T13:10:57.850 回答