SPA with rails-api and Angular JS

Recently, I have been trying to use rails-api, I have a small development project and after watching a small rails-api demo, I thought it would be nice to use it as my server side. I found this tutorial: http://www.angularonrails.com/ruby-on-rails-angularjs-single-page-application/ but there are two separate servers in this tutorial and it seems to me that this is not the way the right way do it.

could not find a good tutorial that explains how to use rails-api to serve REST and say that the server also serves some html / css / js, so my angular SPA will work next to the services.

I have not tried to use RubyOnRails, since I do not need to use in Views, but maby Im wrong?

so my question is: how can I create a one-page application with rails-api (or ruby ​​on rails)?

with one server ...

+5
source share
1 answer

If you want to run everything from one server, just use Rails, not Rails-api. Rails includes everything you need for the API anyway (e.g. format.json, render: json, etc.), but also includes traffic for assets that you can use to serve your SPA.

Create a new Rails project, create a page controller that will serve the index.html.erb page of your SPA, and off. You will not need to touch any other Rails view folders. You can create your own folder + JS folder structure for your SPA, as part of the main Rails project.

You can do this with the Rails-api, but you can import parts of the core Rails libraries to have everything on one server.

+6
source

Source: https://habr.com/ru/post/1246408/


All Articles