Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New 0.9 gem does not work out of the box with rails-api #600

denkristoffer opened this issue Aug 23, 2014 · 9 comments

New 0.9 gem does not work out of the box with rails-api #600

denkristoffer opened this issue Aug 23, 2014 · 9 comments


Copy link

@denkristoffer denkristoffer commented Aug 23, 2014

I'm not sure whether this issue should be opened here or on the rails-api repository so let me know if this is the wrong place.

Anyway, active_model_serializers does not work out of the box with a new rails-api project, as the JSON responses aren't being overridden. I found this Stack Overflow question, which resulted in one solution: making ApplicationController inherit from ActionController::Base instead of ActionController::API. With this I found out that ApplicationController needs ActionController::Serialization for AMS to work.

For those of you that are experiencing the issue, that means that you can just add the following to ApplicationController to work around the issue for now:

include ActionController::Serialization

If this behaviour is intended, shouldn't it be mentioned in the README?

I'm on Rails 4.1.5, rails-api 0.2.1 and active_model_serializers 0.9.0.

Copy link

@steveklabnik steveklabnik commented Aug 23, 2014

I'm going to be doing work on rails-api itself soon, so it's basically that I haven't checked. I'll mark this as a bug, but it's probably one in rails-api, not AMS.

Copy link

@ericbrooke ericbrooke commented Aug 25, 2014

I have the same issue, after update 175 tests fail :-( go back to 8.1 and all the tests pass:

Below are some examples:

  1. HelperDetailsSerializer serializing a helper serializes the min hourly rate
    Failure/Error: json = serializer.to_json
    undefined method `api_helper_url' for #HelperDetailsSerializer:0x007fd91c934430


    ./app/serializers/helper_serializer.rb:4:in `attributes'


    ./spec/serializers/helper_details_serializer_spec.rb:15:in `block (3 levels) in <top (required)>'

  2. Search::User null location location search skips users without lat/lon
    Failure/Error: expect(results.size).to eq(1)

   expected: 1
        got: 0

   (compared using ==)
 # ./spec/services/search/user_spec.rb:156:in `block (3 levels) in <top (required)>'
Copy link

@steveklabnik steveklabnik commented Aug 25, 2014

@ericbrooke if you happen to be able to isolate specific errors not related to rails-api, please open individual ones for them as well, thanks

Copy link

@jspies jspies commented Aug 28, 2014

As a workaround, I found that just adding

include ActionController::Serialization

to ApplicationController works.

Copy link

@denkristoffer denkristoffer commented Aug 29, 2014

Yeah, I mentioned that in my initial post but I might have been rambling a bit too much for that to be clear. I've updated the post to so that people who look here for help should be able to see it easily 😄

Copy link

@MarcusSky MarcusSky commented Dec 13, 2014

I was having the same issue, @jspies's comment did help me! Shouldn't this be added to the project's README ?

Copy link

@sbycrosz sbycrosz commented Feb 2, 2016

I could confirm this happens for Rails 5 with ActiveModelSerializer 0.9.4, and adding the include works.
+1 for adding this to readme 👍

Copy link

@steveklabnik steveklabnik commented Feb 2, 2016

Sure, please send a PR and I'm happy to merge 😄

Copy link

@oyeanuj oyeanuj commented Sep 11, 2016

@MarcusSky @sbycrosz While generating scaffolds with a Rails 5 API project, I ran into the following issue on 0.9x which goes away on 0.10x - did you guys see the same issue?

 rails g scaffold User
Running via Spring preloader in process 20090
      invoke  active_record
      create    db/migrate/20160911170034_create_users.rb
      create    app/models/user.rb
      invoke    test_unit
      create      test/models/user_test.rb
      create      test/fixtures/users.yml
      invoke  resource_route
       route    resources :users
      create  app/serializers/user_serializer.rb
      invoke  scaffold_controller
Could not find "api_controller.rb" in any of your source paths. Your current source paths are:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
8 participants
You can’t perform that action at this time.