Connect Rails with React Native - ruby-on-rails

For a university project I had to build a website in Ruby on Rails and deployed it via Azure. The website is live and running smoothly.
After two weeks the website has been deployed, my professor asked me to create a React Native app using the Rails Backed.
So far, I have created the front-end using React Native BUT I have no clue how to connect it to the Rails backend (I guess I need an API but not sure how to do it).
I googled it around, but there is not a specific tutorial that helps me in connecting a Rails live website with React Native.
I am new to this world and need some guidance in the right direction.

Create a new rails application that functions as the api. You'll have to run the rails new command with an additional --api flag.
rails new rails-api-with-react --api
Move into the directory
rails-api-with-react
Start your server
rails server
Use a tool like [Postman][1] to check that the server is running.
After you confirm that the server is up and running, make a get request in your React application to the Rails server

Related

Networked Ruby on Rails URL/Address?

I have created an app with a Ruby on Rails backend and a VueJS frontend. I have successfully created the desktop version of the app, but I am now testing and tweaking the mobile version to verify cross compatibility.
The challenge that I am confronted with is that I can access the VueJS portion of my app via the local IP address that the VueJS server provides (http://10.0.0.163:8080), but I have no such networked IP address for the Ruby on Rails server.
As such, my app will appear, but it does not function 100%, as the VueJS app cannot reference the Ruby on Rails address (http://localhost:3000) while being viewed on another networked device.
Does anyone know of a way to change the settings so that I can remotely access the Ruby on Rails server from a networked VueJS address?
If anyone has any resources, it would be of great assistance.
Thank you,
DD

AngularJS frontend and Rails backend with AWS in Ubuntu

I would like to discuss about AngularJS and Ruby on Rails working together and deployed in AWS (Amazon Web Services).
So far, I have a development environment with an AngularJS frontend that sends request to a Ruby on Rails API backend. These both are two separate applications (they are in separated git repositories).
The AngularJS app is running in a Node.js server listening on one port, and Rails is running in a Webrick server listening on another port.
Although they work together, AngularJS is not physically integrated in the RoR app.
Now its time to deploy in production environment. For that, I will use an EC2 AWS instance (currently deploying using Elastic Beanstalk). As far as I understand, I can't have the same architecture here.
I would like to know your suggestions this point. Do you see any advantages or disadvantages?
Should I update my development environment, so the AngularJS app is integrated inside the RoR application (and deploy just one application)?
This is something I don't like, because I guess I have to modify many things.
On the other hand, is it possible to run both applications separately, the same way I do in development?
Can I install a node.js and a Unicorn or whichever server manually in production in the same instance?
I finally deployed with two separated applications as described above. The main difference is around the servers. My AngularJS frontend finally runs on an Nginx. And my Rails API is running on a Unicorn.

Viewing project on browser

I am new to ruby. I can view my project on browser when I write ruby script/server otherwise I can't view my project on localhost.
What I have to do to view my project always on browser?
If you are using ruby on rails for the first time . Your answer is detached(deamon) mode .
Make sure your ruby version is more then 1.8.6 and rails version is less then 3.x.x
Script is
ruby script/server -d
And to know more
ruby script/server --help
When you use your application (using a browser) the application's code is run on a web server that receives the requests, execute the right code and respond to the user.
Now, rails provide a simple web server that you can run with rails server and you can use to test and develop your application. This web server is run on your machine and when you go to http://localhost:3000/ it's that local web server that responds.
If you want to access your application you need a webserver running. If you want to access your application anytime from everywhere the application must be in a server accessible from everywhere but you first need to deploy your application.

How can I start up a ruby server script when I start up my rails app?

I'd like for a ruby server script that lives in my rails app root folder to accept connections from clients (the clients are not browsers--not that this really matters i guess) and update the db of my rails app while my rails app is running. Therefore, I'd like for it to be told somehow to start running whenever my web server starts serving up my rails app and stop running whenever my web server stops serving my rails app. How can I do this? Is this as simple as putting the name/path of my ruby server script somewhere?
You should look into Foreman, a gem specifically for launching multiple processes in your server environment.

Is it possible to integrate a nodejs app as a part of a rails app?

What's the best way to integrate a NodeJS app into an existing Rails app?
Rails app: http://www.rails.app
Nodejs app: http://node.rails.app or even http://www.rails.app/node
23-09-2010: After searching for some time, I think an approach would be to have 2 separate services:
Rack (Rails) service, which would host the rails application.
NodeJS service for the realtime component.
So, I guess what my question is aimed to, is server management: How can I properly configure a server to host the main app via any requests to http://www.rails.app/* but dedicate http://node.rails.app or http://www.rails.app/node to the nodejs component?
Just use Juggernaut 2. http://github.com/maccman/juggernaut
However, i would advise you to just stick to one of them. Either node.js or Rails. For rails you can give http://pusherapp.com a shot.

Resources