CORS or ActiveModel Serializer (ember+rails)(ANSWERED)

Hi, i want to use rails api as backend but i am new and i actually have never done it.

I have seen some tutorials, some of it users CORS (cross origin resource sharing), and some uses Rails Active_Model_Serializers.

Which would be a better solution or are they different things from each other?

If they are totally different things, when each one should e used?(e.g, for devise auth ppl use CORS in the tutorial)

They are completely unrelated.

CORS is something that you don’t have a choice about, if you’re doing cross domain requests it’s required.

active_model_serializers is a gem for serialization. You can serialize however you want on the rails side, there are many competeing serialization libraries, or you could just build your json manually, but that’s not a very scalable approach

Thanks.I am new to both of them and i can’t seem to combine them.Tried 2-3 different tutorials but they all error out.I can’t get the full error right now but it is something like this."Reference error.ActiveModelAdapter, must contain one of the following data, model,

ActiveModelAdapter is a third thing that’s only tangentially related. I suggest using some kind of serializer to render json-api, and using the default json-api adapter on the ember side

1 Like

Thank you.I will try as soon as possible.

Have you considered using ember’s proxy feature instead?

1 Like

you mean this “ember serve --proxy localhost:3000” yes and it didn’t work.They connect each other, i see it on the inspector but still same mistake.

Strange, it removed all CORS issues for us.

Maybe, you can add “rack-cors” gem to your rails project. bookstore-api/Gemfile at master · zoltan-nz/bookstore-api · GitHub

This is a quite lazy configuration, probably it can be more strict in production: bookstore-api/application.rb at master · zoltan-nz/bookstore-api · GitHub

Thank You all for helping out.I have gone over a different tutorial Ember and Rails 5 with JSON API: A Modern Bridge - Ember Igniter by Frank Treacy, and it worked perfectly.Special thanks to him for the turorial :slight_smile: The one with the CORS was old and i think the part where configuration is made was forgotten but i might be wrong tho.Again, thank you all :slight_smile:

1 Like