Intergrating Rails with Cordova/Phonegap - ruby-on-rails

I'm now making a hybrid app with Vue.js/Cordova/Phonegap + Rails 5 api.
I've searched a lot about this and just following the existing path.
But I'm wondering why I can't directly integrate rails with cordova and couldn't find any explanation about this.
I think Vue.js's component way could be similarly made by Rails' partial render. If this integration is possible it would be much easier for rails developer to make SPA without additional frontend framwork.
As far as I understand, cordova itself is a webview, then why is this impossible?
Can anyone explain why?

Related

Rails API, JSON - how to connect to a web app and bring tables to life?

Hello!
First of all I would like to let you know that I am a fairly new to programming (mostly Ruby on Rails). I have been studying by myself for around 6 months. I recently got a first project - a voting app.
I have created the layout to the app - using HTML, CSS, bootstrap, a little JS and JQuery.
Now I need to bring the app to life - so, make the tables alive. I have heard that it shouldn't be hard to do in Rails API (using REST), which I have created with the help of some tutorials (like this guy). The webapp will be used only locally, on a device.
So, my questions is:
How to connect Rails API to the layout and make it "talk" to eachother?
I know I should use JSON to communicate the front end with server, but I am not sure where to start.
Thanks in advance!
If you're trying to make a website you should follow this tutorial. APIs are more for sharing your sites data or functionality with other sites, or for serving data to mobile apps/frontend frameworks like AngularJS.

Getting started with React and Rails

I have started a new project in which I would like to use React and Rails. This project is on the small side and will require some basic interactive UI, hence React. As far as I know there are two ways I could get started with this:
Using the react-rails gem and use the built in view helper
Create a Rails API and React/Flux frontend app
I have a few questions however. In no particular order:
React-rails seems like the simpler solution, but what drawbacks would I be facing?
I come from a Rails and Ember background so the Rails API + React FE solution makes architectural sense to me. But with the react-rails gem I'm confused on how some things should be done. Primarily, how do I handle routing? I suppose I won't have access to any react route helpers and will need to pass paths into the react components as props?
Thanks in advance!
For a small project React-Rails, https://github.com/reactjs/react-rails, is great I have used it in production the last year on 2 sites that get about hundred thousand visitors a month and I haven't had any issues.
That said if you want to use Redux, React-Router or Flux don't use React-Rails go the API route.
My rule is if you are just using React components then use React-Rails.
If you are doing a Redux, Flux app then just make a frontend app.
It depends on how much your server is doing and also your team. If you have a lot of business logic that you want to keep in Rails, then you may want to have that logic running on a dedicated Rails server and expose as APIs.
You can then have a NodeJS server that does nothing but fetch data from APIs and render React to send to the users. The only interaction between react and rails is via the APIs as JSON. This basic setup will scale really well and is a pretty simple mental model.
If the project gets bigger, this means you can have JS-only devs work in JS only and Rails devs work in Rails only. Plus if you want to move away from Rails or React later, there's no added complexity there.
OR
If all your devs are React+Rails and the project is a bit small for multiple servers, then I think using react-rails to serve up your pages is a fine solution.

Intergrating Angular JS with rails

I need some guidance to figure out how to incorporate Angular inside rails.
Reason for choosing Rails : I like their opionated approach to do things right. Also migrations, gems are really cool.
Reason for angular : I was researching and looking for framework best suited for SPA. Backbone seem too abstract. I had choice to make between Angular & Ember. I started reading Angular first and it made sense to me. So i never went to read about ember.
Reason for Angular & Rails: I researched and tried using small scale framework like grape, slim ( Yes i use php too ). But i feel need to stick to rails for long term scope of project. And personally i like doing things rails way.
So here is where i need help,
I have rails project in Rails 4.
Sign-in , sign-up everything is created as followed in Michael Hartl tutorial. Have tweaked stuff based on my requirement.
So post-sign-in or post-sign-up steps a view from show action of users controller is rendered.
I figured i'll need different layout files so i created same for outer pages and inner pages, respectively.
I don't know how to proceed i want to make use of the angular templates and routes for my single page app ( which resides post sign-in ). I am flexible if there is another way. I just need a guide how to use angular seemlessly with rails making use of rails controller to handle my rest request and using routing provided by angular to navigate around in SPA.
Hope i am clear. Feel free to edit this.
here is a great railscasts from ryan bates: http://railscasts.com/episodes/405-angularjs
also here is the source for that railscasts you can get ideas from there:
https://github.com/railscasts/405-angularjs
I'm not familiar with SPA, but I have been working on a tutorial for integrating rails and angularjs, which I'm refining over time. It may provide some answers here - in particular I am using the angular routing to provide a single-page app as you describe: http://technpol.wordpress.com/2013/09/03/angularjs-and-rails-tutorial-index/
I would suggest you to not mix angular into your rails app. Keep both of them separate.
So you could either place the whole of your angular app in the public folder of your rails app or keep it completely away from the rails app. This is more like a service oriented architecture, where your rails app serves as a back end serving as an api and the front end(Angular app) consuming that api.
There are many many nice articles the covers how to handle the authentication/authorization
in angularjs with REST APIs.Authentication with AngularJS and a Node.js REST api
Coming to the rails side for building REST API, Grape is a nice choice. Here is a nice series explaining some best practices about grape.
HTH!
I'd suggest taking a look at this tutorial: How to Wire Up Ruby on Rails and AngularJS as a Single-Page Application. I have used it for a few personal projects, so I am sure that it is up to date as of late 2014. If you want to view it in action you can head to http://goodmatches.herokuapp.com, and you can view the repo.
Try half-pipe gem which makes using bower for managing javascripts assets much easier.

Ruby on rails making an app for smartphone

I want to build an app that use in the backend Ruby on Rails. However my problem comes in the lack of information i found on it. My goals is not just to create a website but an application that interacts with it, like my android facebook app when pressing menu I get button like logout and so on.
I am wondering if their exists tutorial on how to build an application but using rails or should i scrap my entire website and do it in php. I am looking for guide and tutorial. Thanks in advance
You can build an app on any platform and make it interact with your Rails-based server using HTTP requests (like AJAX).
You can send information back and forth using JSON or XML; you would probably need to make a new set of actions for the app to use.
There is no reason to use PHP. ever.
A little unclear from your original question, but if you are looking to create a mobile app using Ruby (and a structure similar to Ruby on Rails) then you may be interested in Rhomobile. It is a cross-platform mobile application framework that uses Ruby for its backend code, and follows a structure similar to (older) Ruby on Rails versions.
From what I understand of your problem, you want to use the robustness of Ruby to develop a native app (not just another app that mirrors a website).
The best thing I know of for this is RubyMotion. The bummer is the cost ($200). But then you would get to accomplish your task.

how to organize structures for a mobile app for cross platform usage in phonegap

i'd like to build a simply application with rails that will include the backend and with json response for a backbone.js app that will integrate the ui framework of jquery-mobile
(inspired on this article and the videocasts of ryan bates's site)
before i'm doing something complitely wrong i'd like to ask you if is better:
to build the backbone.js/jquery-mobile application apart rails structure but with the eco template for a better integration with phonegap for publish the app on the apple store
or
is it possible to mantain all the structures all togheter with the backbone-on-rails gem like ryan had illustrated in the 2 videos and after compile all with phonegap with specific steps?
i hope that the question is quite clear!
I would personally familiarize myself with one of the two first and then port my knowledge to integrate the second.
First, it would be a good idea to keep Rails as your server REST API and database. You can develop your app with backbone and Rails just like you saw Ryan do.
Second, once you are familiar with Backbone and your structure is working, it should be much easier to take everything and compile a simple application using PhoneGap.
One step at a time, better testing, better understanding.

Resources