Using rails with phonegap - ios

I have a fully functional rails app but, I want to create a mobile version using Phonegap. I've got Phonegap and Xcode set up but, I'm not quite sure how to go about it.
I want the mobile version to pull from the same database as the web version.
What technology can I use to achieve this?
Thanks,
Ramario

You should probably expose your database through a REST API abstraction layer either with Rails or a separate application using something like Sinatra, which I personally find better suited to API development.
Then your mobile app can make REST calls to allow users to manipulate data from the same database.
Or you can of course just make your existing web UI mobile-friendly and have people just as easily work with your Rails app through the browsers in their phones as they do the browsers on their laptops.

Related

How do I link two apps in node.js and rails?

I run a social network app built in ruby on rails 4. We want to improve it and add realtime and add live streaming features. We also want to make 'likes', 'comments' features real time. My lead programer says ruby on rails is not good for this and not possible and only way is to do it in node.js however doesnt know any solution to link node.js application to rails. I'm a business guy and not technical and need info to let him know it can be done.
Rails 4 doesn't have streaming(like websocket, maybe streaming is not good word in this context) functional from box, but many gems exist for this: https://rubygems.org/search?utf8=%E2%9C%93&query=websocket.
However you can use websocket.io if you decide it is a better solution, for example, in my current project we use websocket.io for send a notifications for mobile application through websocket: rails and nodejs exchanging data through Redis.

Rails multi-client app - Should I really use an API / json?

I am building a ruby on Rails 4 app. The web version is ready and I would like to set up/learn how to build mobile apps.
I know and read in many many articles that the "way to go is to use rails-api and feed json to the various clients".
But I'm not sure it's the best fit: I don't want to use it only because it's popular. I want to understand why (if it is) really necessary.
I'd like if possible to build a "beautiful monolith" as explained here.
DHH (core creator of Rails gem) use in Basecamp this beautiful monolith strategy, an hybrid approach which he states is the number 1 time-saving tactic they use to be able to maintain with few developpers numerous web and mobile apps.
Basically you keep your Rails controller, Rails models and everything in your Rails app and rails app and you use a phonegap container to inject in web views the views. You only change this way the views (with Rails 4.2 variant).
https://signalvnoise.com/posts/3766-hybrid-how-we-took-basecamp-multi-platform-with-a-tiny-team
So with this strategy, let's take an example where we need to the database data. for example if someone loads my mobile app:
- the webview 'homepage' on iphone will load ex: views/phone/projects/show.html.erb:
say I need to display the name of the user in this page, the app will go fetch it on /app/controllers/homepage_controller.rb and this controller will have a method like #users = User.find(id)... (active record)
so IT WILL GO HIT THE standard DATABASE (without needing any api or json)
So when I asked 'I'd really want to know why people sue rails-api/josn to know if I really must use it, or if I can use DHH hybird approach', here what people say
80% of start ups use it => blah...not a reason enough. I'd like to know why I should do it.
you can't do "single page apps" and ajax calls without API/json
Here I checked and it's incorrect: as explained below, you can totally use ajax in a webview can totally do it via whitelisting:
http://www.telerik.com/forums/$-ajax-not-working-on-android-devices :
When you are developing a Cordova powered hybrid app, you do not need to make CORS requests. Regular XHR requests will work without a problem. The reason for this is that a mobile app is executed from a file URI and does not comply to the cross origin policy. Mobile apps have an alternative to this policy which is called domain whitelisting.
Are pure and traditional Ajax Requests possible on native / hybrid mobile apps?:
PhoneGap apps run in webview not in browser, so cross origin is not an issue with PhoneGap apps, you can perform AJAX calls to any URL. The only thing to care of is that there is a white list parameter "access origin" in config used to restrict the access to some specific URLs.
So if I follow DHH hybrid approach to keep my Rails app but change the views on the web/iphone/android views and use my database data WITHOUT any API or json, is it possible?
What does API/json really bring to the table, why would they be really necessary, explaining most large multi clients app use them? Can't each of my various apps (web app, mobile app, tv app) just hit the database without any API/json ?
I might be missing something obvious so please advise.
This question does not really suit stack overflow, as the answers can be very opinion-based and also depend on what YOU really want to achieve. However, I will have a go:
Your first question:
So if I follow DHH hybrid approach to keep my Rails app but change the
views on the web/iphone/android views and use my database data WITHOUT
any API or json, is it possible?
Yes this is possible. Note that it will not be a 'native' app on the mobile device, and many people consider such 'apps' to be inferior (since they are not really apps installed on the device). The big advantage of course is that you don't have to learn how to write a native mobile app (and an API for it to talk to). The other big advantage is that you only have to maintain one code-base (models and controllers) for serving all users. You should really google native apps versus non-native to see the full picture.
Your next question:
What does API/json really bring to the table, why would they be really
necessary, explaining most large multi clients app use them?
Separating the API out from the 'front end' part of your code base allows you to have different teams develop different frontends. So you might have a mobile team that focuses on building a very polished mobile native app. You can also have a backend team focus on the API. So for larger enterprises this makes a lot of sense. The API is also more easily scalable - you can have multiple servers running the API and as more 'frontend users' connect (whether form mobile or web or whatever) you can bring up more copies of your API to serve their needs. The other option you have is to easily open-up your API to 3rd party developers if the need arises. That would be a bit harder with the DHH hybrid approach. Not impossible, but harder.
Your last question:
Can't each of my various apps (web app, mobile app, tv app) just hit
the database without any API/json ?
Yes, of course. This is really the same question as the first. Your different views would be serving different 'frontends' (basically HTML/JS/CSS) for the different clients. But they all hit the same controllers/models and hence database. Just don't forget that all your clients are HTML based. Most mobile/tablet users don't like having to open a browser to use an 'app'. They want the native experience (same goes for tv boxes, consoles etc).
By the way, there are ways to develop mobile apps that share one-code base (see appcelerator.com for example). But that's yet another, and different, approach!

What exactly will the architecture for a Rails app and mobile app look like?

So I am creating both a Rails app and they are getting a mobile app created for their project.
I would prefer to use Heroku and that whole tool chain because I love it. It is simple, has lots of caching add-ons, is cheap/free on the low-end and can scale up easily.
However, they want a mobile client that can also do the same thing the Rails app can do.
It obviously doesn't make sense running two different databases (one on Heroku and the other on Parse - which is what they want to use).
So how do I setup both apps to use the same DB?
Do I just create a public-facing API from the Rails app and have the mobile client ping those endpoints?
Do I use Parse for the mobile stuff, and write the Rails app to use the Parse DB instead? Is Parse a suitable Heroku replacement for serving cached files and scaling up as needed, etc.?
Do I maintain two databases (one at Parse and one on Heroku) and just create a Rake task that syncs the two?
What's the best way to approach this problem, so we keep the entire project as DRY as possible and also future-proof it so when we want to add more mobile clients and perhaps other clients in general, we can easily just add them on to the existing infrastructure?
I see many developers using Rails to deliver their API while taking advantage of Ember or Angular to build the front of the application. It makes it a lot easier to build the mobile app at the same time.

Need to build mobile UI for a Rails app

I need to begin building a mobile UI for one of my Rails apps. A quick search brought me to the Titanium platform. Any thoughts on using this? Alternate suggestions are also welcome/appreciated.
In addition to my app rendering HTML, I am also able to easily create an API that will render JSON -- if that makes any difference regarding an answer.
Thanks in advance!
No experience with Titanium, but I would start with a Web UI, optimized for mobile (small) devices. This would avoid you to build several (well, two : one Android and one iOS) different clients applications.
Many current web framework now help with building mobile web application (look at Twitter Boostrap responsive features for an example).
You may want a native app afterward, especially if :
You want to interact with the phone/device (get contacts, push notifications, use sensors)
The native look and feel is very important to your application
Even so, a lot of very good apps are actually "hybrids", mixing native widgets with webview (take a look at 37 signals discussion about their new Basecamp iOS app).
In addition, if you are going the native way and are a Ruby developer (which I suppose), you may want to take a look at Ruboto (that allow to code applications for Android in Ruby) and RubyMotion (same for iOS).
I've decided to further pursue using Titanium and will most likely be creating a hybrid app. That said, both JQuery Mobile and Twitter Bootstrap also look nice! Thanks everyone for looking.

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.

Resources