Ember JS with Rails API


#1

Hi folks. can you help me?

In the company where I work, we have a project that currently both the back end and the front-end are in Rails. Of course, we realize that this structure was tied up costing us more hours in each new feature or maintenance.

Thinking about it, we divide the project into parts that make sense:

1 - API rails, but while the Rails 5 not out of beta, we will use the rails-api gem;

2 - Back-end on Rails, because we keep all business rule we already have;

3 - Front-end in EmberJS in version 2.3.0.

Basically the operation is as follows: the rails in the back-end run our processes and save the data in the base (as is the case today), the front-end API query that in turn query the data in the base.

We never use EmberJS here, so I do not know what the best practice and on their own could not find anything that expliacasse me properly or I could understand correctly

My questions are:

1 - When creating the EmberJS project, I have to take the ember-date?

2 - I must use RESTAdapter or ActiveModelAdapter and why?

3 - What is the best way to structure the server? For example the url http://app.meuprojeto.com points to the front end and the url http://api.meuprojeto.com points to the API, the API has to be within the Front End folder or they can be “sisters folders”?

4 - Say I have the users table in the back-end with 15 fields, however, the front-end I will only display or edit five fields in the model I have to identify the 15 fields or only those who will view / edit?

5 - What is the best way for me to create the urls that will to set the API?

Sorry if the questions are too frivolous, but I really could not find somewhere that retiresse me these questions. And in the city where I live I have no contact with anyone who knows the EmberJS.

Thanks in advance!


#2

Hi Danilo! That sounds like a great plan.

Regarding your questions:

  1. I suppose you mean Ember Data, and yes, I would recommend it

  2. The choice of your adapters and serializers are determined by your backend. Frontend and backend will communicate – you need them to speak the same language, whatever that is. If you are free to choose, JSON API is a good standard to follow. However, if you are more conservative judging by you keeping Rails 4 (and that makes a lot of sense) you could try ActiveModelAdapter. Why? Because it’s very likely talking the same “default” language of Rails 4. More info on adapters/serializers here: http://emberigniter.com/fit-any-backend-into-ember-custom-adapters-serializers/

  3. You can choose whatever URLs you like and set up CORS for that. If you serve the index.html (frontend) from the same domain of the API that’d be easier.

  4. No

  5. I would follow Rails conventions, but in the end it doesn’t matter. Ember Data is powerful enough to configure to work with any backend endpoint structure


#3

Hi Frank,

Thank you for your help. In fact, I’m following the advice of your blog to understand EmberJS. Your articles are great and explained very well.

1 and 4 - Thank you. At this point on the Ember-data, doubt is linked to item 4. I wondered, as I did not understand if I would have to have all database fields listed in Ember-data or only those fields that I will show on the front end.

2 - At this point it is a stalemate. The application will be in Rails 4 for a while but when the Rails 5 is released, the plan is to migrate to it. So I’ll have to read more about it (thanks for the article, I will read more carefully), but I can use the JSON API with Rails 4? So I will not need to change any application call when the Rails 5 out of beta.

3 - This will be the same domain. For example: app.myproject.com and api.myproject.com

5 - Nice.

Frank, once again, thank you for your help and sorry for my english. People say that EmberJS community is much smaller than other frameworks. I see that quantity has no relevance with quality. I spent two weeks researching all the front-end frameworks that could be used here in the company, to perform this migration. The people here trusted when I said that despite a smaller community, the EmberJS beyond the fact that Rails Like, has a more mature community and willing to help those just starting out.


#4

Hey Danilo, thank you! I agree, this is a very helpful community and Ember a mature and productive technology (despite a few remnants from the view/controller dark ages)

  1. You can definitely try JSON API with Rails 4 in preparation for Rails 5, I never did – let us know how that went.

  2. I’m pretty sure you will have to use CORS, but that’s easy since you control both back and front-end