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

Closed
denkristoffer opened this Issue Aug 23, 2014 · 9 comments

Comments

Projects
None yet
8 participants
@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.

@steveklabnik

This comment has been minimized.

Show comment
Hide comment
@steveklabnik

steveklabnik Aug 23, 2014

Contributor

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.

Contributor

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.

@ericbrooke

This comment has been minimized.

Show comment
Hide comment
@ericbrooke

ericbrooke 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
    NoMethodError:
    undefined method `api_helper_url' for #HelperDetailsSerializer:0x007fd91c934430

    ./app/serializers/helper_serializer.rb:21:in`url'

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

    ./app/serializers/helper_details_serializer.rb:6: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)>'

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
    NoMethodError:
    undefined method `api_helper_url' for #HelperDetailsSerializer:0x007fd91c934430

    ./app/serializers/helper_serializer.rb:21:in`url'

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

    ./app/serializers/helper_details_serializer.rb:6: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)>'
@steveklabnik

This comment has been minimized.

Show comment
Hide comment
@steveklabnik

steveklabnik Aug 25, 2014

Contributor

@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

Contributor

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

@jspies

This comment has been minimized.

Show comment
Hide comment
@jspies

jspies Aug 28, 2014

As a workaround, I found that just adding

include ActionController::Serialization

to ApplicationController works.

jspies commented Aug 28, 2014

As a workaround, I found that just adding

include ActionController::Serialization

to ApplicationController works.

@denkristoffer

This comment has been minimized.

Show comment
Hide comment
@denkristoffer

denkristoffer 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 😄

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 😄

@MarcusSky

This comment has been minimized.

Show comment
Hide comment
@MarcusSky

MarcusSky 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 ?

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 ?

@sbycrosz

This comment has been minimized.

Show comment
Hide comment
@sbycrosz

sbycrosz 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 👍

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 👍

@steveklabnik

This comment has been minimized.

Show comment
Hide comment
@steveklabnik

steveklabnik Feb 2, 2016

Contributor

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

Contributor

steveklabnik commented Feb 2, 2016

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

@oyeanuj

This comment has been minimized.

Show comment
Hide comment
@oyeanuj

oyeanuj 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:
/Users/anuj/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/active_model_serializers-0.9.5/lib/active_model/serializer/generators/serializer/templates

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:
/Users/anuj/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/active_model_serializers-0.9.5/lib/active_model/serializer/generators/serializer/templates
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment