active_model_serializers icon indicating copy to clipboard operation
active_model_serializers copied to clipboard

Add missing api_controller that Rails 5 generator expects

Open oyeanuj opened this issue 6 years ago • 5 comments

Purpose

This allows AMS 0.9x to be used with Rails 5, without any errors.

Changes

Added an api_controller.rb template that the Rails 5 Generator expects.

Caveats

This fixes the main issue that I was facing in #1923 but as I experiment more, there might be more issues getting Rails 5, AMS 0.9x to play well.

Related GitHub issues

#1923

Additional helpful information

Thanks @bf4 @remear for your help debugging this issue.

oyeanuj avatar Jul 27 '17 01:07 oyeanuj

@oyeanuj Sorry for the delay in responding to this: what's the error? I'm not sure why AMS should be adding a controller generator template

bf4 avatar Aug 13 '17 02:08 bf4

@bf4 So, it seems that Rails 5 in API mode expects there to be these controller generators which were missing and causing errors mentioned in #1923.

Also, to point out that 0.9x already had controller template but it was named controller.rb. In API mode, it seems to expect the controller generator to be named as api_controller.rb.

oyeanuj avatar Aug 20 '17 15:08 oyeanuj

ref

  • rails template https://github.com/rails/rails/blob/5-1-stable/railties/lib/rails/generators/rails/scaffold_controller/templates/api_controller.rb
  • devise template https://github.com/plataformatec/responders/commit/8f443b2f185b04816cb0e990d50832a015ca2594

bf4 avatar Nov 02 '17 14:11 bf4

@oyeanuj would you be up to rebase and force push this?

bf4 avatar Nov 02 '17 14:11 bf4

I think it might make more sense to avoid the api controller template. There's nothing different in it from the Rails default, right?

module Rails
  module Generators
    class ScaffoldControllerGenerator
-      if Rails::VERSION::MAJOR >= 4
+      if Rails::VERSION::MAJOR >= 4 && ApplicationController < ActionController::Base

bf4 avatar Nov 19 '17 21:11 bf4