recently I'm trying to use rails-api, I have a small project to develop and after seeing small demo of rails-api I thought it will 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 in this tutorial there are two separate servers and It's seems to me not like the right way to do this.
couldn't find any good tutorial that explains how to use rails-api to serve the REST and tell the server also wo serve some html/css/js - so my angular SPA will run next to the services.
I didn't try to use RubyOnRails since I have no use in the Views but maby Im wrong?
so my question is: how can I create Single Page Application with rails-api (or ruby on rails)?
with one server...
If you want to run everything from a single server, just use Rails, not Rails-api. Rails includes everything you need for an API anyway (i.e format.json, render :json etc), but also includes the asset pipepline which you can use to serve your SPA.
Create a new Rails project, create a pages controller that serves the index.html.erb page of your SPA, and away you go. You then won't need to touch any other Rails view folders. You can create your own folder + JS folder structure for your SPA, within the main Rails project.
You could do this with Rails-api, but you would find yourself importing parts of the main Rails libraries to have everything on the same server.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With