Ruby on Rails to Ionic - ruby-on-rails

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

Related

How to get Rails and all requirements running to use React?

Iam a novice in rails and trying to write my first React frontend. I have read enough to know that there are different methods to use React with rails. I decided to split frontend and backend, and use rails in API mode. I cannot find good sources explaining what I need on my server to get rails and react going, and why. I read so far about npm, node.js, Heroku and so on, but i lack the knowledge to decide what to pick and i dont understand the interactions yet.
Does someone know a good tutorial, some sources or keywords to point me to a direction?
If you want to use Rails just in API mode with React on frontend then you can separate those apps completely.
I.e. use Rails/Puma server for API and have a separate server (Nginx/Apache/Node.js) to serve the frontend React app and other static assets.
For using react as your client-side application and rails for the server-side you need two different applications. As Rails is MVC I suggest you use just ruby and Sinatra server.
In this situation be careful about the cross-origin errors you have to enable it while using two agents.
Take a look at this.

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.

Should we use Rails routes or React routers

I am new with React and today I was working on react-routers. I am not clear which routes to use. My choices are Rails routing or React router. What are the difference between these?
React should be used for rendering and Rails should be used for the API.
Each react app should have its own server-rendered path, with calls to a rails API on the backend. The API should definitely be routed with rails, but only pass back the data you need to the react app. Rails 5 has ApiController you can use for your controller superclass.
TL;DR - React is frontend, rails API on the backend.
Also, you should really determine if you need something so heavyweight on the backend. Some lighter ruby alternatives are Sinatra and Padrino.
You can use them for both server side and client side. If you are fully MEAN stack then you can use that. If you are in Rails stack then it's not possible.

Can i use Rails to make a phongap app

Can i make a website using rails (database backed ofcourse) and use phonegap to make a native app vertin of it ?
I know that phone gap is agnostic of back-end technologies but i didn't find any answer for my question.
You can't. Phonegap consist only in HTML, CSS and Javascript. You can build up your web service either REST or SOAP API using Rails.
Reference: http://blog.revivalx.com/2014/07/15/simple-hybrid-mobile-app-using-cordova-and-ratchet-2-complete/

Can we use Ruby on Rails to develop a mobile app?

Since Rails uses MVC architecture. I was wondering that if we can use Rails to develop a mobile app or any web app.
Out of MVC the 'M' and 'C' won't change to develop the mobile app right?
I mean the models and controllers will remain the same.
Only the view portion should be changed such that, instead of using html.erb files I want Java or Android SDK or whatever, to provide the UI for the mobile user.
Can someone enlighten me on this perspective?
Also I have been hearing about jRuby does it come into play for our mobile app development requirement?
The answer to this question is going to depend on how you want to deploy this app. Do you want it running completely on the phone or can it be a web app disguised as an iphone/android app?
For the native app solution I'd checkout the Rhodes Framework. It's not RoR but you'll see that it's an MVC framework that feels similar. This will allow you to build native iphone/android apps using Ruby.
For the 2nd option, web app disguised as a mobile app, I'd recommend Sencha Touch. Sencha has done an amazing job mimicking the look and feel of native iphone/android apps with their Javascript library. With this solution it would be just like any other web app though it's targeted for android and iphone via it's UI.
I've created an example rails / ember.js App that is exported with Phonegap. It uses just the usual MVC architecture of a Rails and an Ember.js App. Maybe you will find it useful. It also implements token authentication based on ember-auth and several OAuth strategies.
Currently in de the devel branch: https://github.com/joscas/base_app/tree/devel
Heroku deploy: https://starter-app-staging.herokuapp.com (the desktop version)
Exported with phonegap-rails gem (of which I'm also the author) for assets, fix paths etc.
Absolutly YES!
Ruby on Rails just a backend tech, is the same as what you plan to do for normal browser. There are only two things that you need to consider about mobile app. First is mobile browser's content size because you need to adjust your layout to fit the size. There is a HTML meta tag called viewport can help you.
Ex.
This script will tell user's browser that the content should be fit the devise size,initial-scale defines the viewport rate and maximum-scale defines how many times this page can scale, and user-scalble=0 means user cannot scale the page. More about viewport you can check the Mozilla's doc.
The other thing you need to consider is the HTML5 techs, but actually these aren't problems when you are using jQuery mobile. I recommend you to check their docs. This is very useful and clear for anyone.
RubyonRails is web application framework - it is running on server and user observer the result of application built on RubyOnRails inside browser(or Browser component), despite the fact that you can process on server just "M" from "MVC", and implement "V" and "C" fully on client side( in mobile browser).
In theory, you can fully deploy RubyOnRails application on client side( even RubyOnRails server and etc), but it will be rather expensive and hard, but it is could not be require in any rational project.
assuming:
There are two way you can choose:
Organize RubyonRails application on the server(process there Model), and process "V" and "C" on client side with any proper js libraries.
You can develop Ruby(not RubyOnRails application) - at least it is possible to develop for Android with JRuby.
Yes you can . Your view can be an web page/android/ ios application as view.
You may want to try jQuery Mobile (which is still in alpha by now) if it's just a matter of UI. If you need a tighter integration with your mobile, I don't think that running Rails would be efficient enough.
Try using React Native, the backend technology can still be Ruby while the front-end can use React Native to build mobile app both Android and iOS.
React Native

Resources