Rails Frontend, Backend, and API - ruby-on-rails

Does your Rails app have to be API-Only to be able to use the API generator? I want to create my fronted and backend using Ruby on Rails. Then build a mobile using the API.

Does your Rails app have to be API-Only to be able to use the API
generator?
No, it can be a normal web application and you can build an API alongside it. The term API-only came from Rails 5 where it introduced a way to generate a Rails API-only applications that are different from normal web applications. For more information, have a look into these guides

You can access your API throught a different route, as in www.myapp.com/api/request, and access your Rails application throught www.myapp.com/request, for example

Related

Existing Ruby on Rails web app on Heroku (PostgreSQL), Devise authentication, need to add Rails API for mobile backed

I have an existing RoR web application which currently uses Devise for authentication.
I am planning on adding API functionality in one manner or another for a mobile backend.
Would you recommend adding API functionality to the web application and using JWT, for example, to enable mobile authentication. Alternatively, would you have two separate applications, a web application and an API, sharing the same Postgres instance on Heroku?
I see pros and cons both ways, but it would seem to me that separating it into two applications would outweigh adding API functionality to the web app. Perhaps, it would make most sense to start over with just an API and add mobile app client and web application client functionality.
Creating a new API only backend might be easier at first, but you would have to copy all your app logic in the models over and keeping both sides up to date will be a pain. You can do it in the same rails app if you namespace the new API so that all calls are under a /api_v1 or something like that. Here is an article that show how you can have different versions of your API.
JWTs for authentication is a great way of doing it and Devise can support them by adding a gem like devise-jwt since adding a route and handling the creation and updating of tokens by yourself is a lot of work.
For the API itself you might want to consider using JSON:API with the jsonapi-rails gem or GraphQL with the graphql gem. This way when someone wants to use your API they can use an adapter for their framework that can talk to that kind of API and not have to worry about the structure of what it returns. There are adapters for both APIs that work with Andrioid, IOS, Ember, React, and all other major frontend frameworks.

Token-based Authentication - Ruby on Rails

I need to generate a User and Admin login page. I followed the instructions contained in the following link. https://www.pluralsight.com/guides/ruby-ruby-on-rails/token-based-authentication-with-ruby-on-rails-5-api What does api-only app mean?
In normal applications the web pages will be generated and given to browsers. The api-only apps the views will be generated by client apps which runs on browsers. The front-end frameworks will helps you to generate the page according to the data provided from server usually JSON. If you are creating applications which runs on web and other platform specific apps, then you have to create API's using which you can run single app server which serves request independent of platform. You can dive deep into architectures like REST, frameworks like Angular, Backbone, React.
Here the complete guide.
Using Rails for API-only Applications
Update:
For JWT auth I will recommend to use Knock. This is tested and simple solution.

Is it possible to add Shopify app to already existing Ruby on Rails web app?

I want to integrate my web app with Shopify which means I have to create my own Shopify app. I noticed that Shopify requires self hosting so it would benefit me to add the Shopify app as part of my already existing web app because I can host it together.
Does this seem possible or do I have to make a desperate application?
It should totally be possible to add a shopify app to your existing ruby on rails project.
If you look at https://github.com/Shopify/shopify_app all you have to do is add in shopify_app to your gem file and then generate the proper routes. You can use their built-in generators or manually make the routes yourself.
Basically you would just need to make additional routes for your existing application to handle the requests to and from Shopify.

Ruby on Rails to Ionic

I have a working Ruby on Rails application that I would like to bundle with Ionic.
How do I show my RoR pages in the Ionic app? Do I have to treat it as an API? What happens to the RoR styling?
I have read http://www.dovetaildigital.io/blog/2015/8/21/rails-and-ionic-make-love-part-one but am unsure how to make this work for my application.
Thank you!
The recommended way to access dynamic information from Rails application is to use API. The trick is to use RESTful routes to handle HTTP calls when you develop your RoR application. Check out this article. Of course you can point ionic (basically phonegap) to load externally hosted mobile friendly RoR application if that fulfills your need reasonably.
Your best bet for rendering data from the Rails backend in an Ionic app is to access the data as JSON.
See the documentation on the Angular HTTP module here.
https://docs.angularjs.org/api/ng/service/$http
Another option would be to return HTML, but you'll lose a lot of benefits on Angular presenting it this way.
Thanks,
Dan

Ruby and Backbone.js

I am looking to write a web application using RoR for the backend and Backbone for the front-end. The Web app will have to list all the member documents.
Does anyone have any experience with running RoR and Backbone.js? How can we call REST API of RoR using the Backbone.js.

Resources