Ghostbusters on Rails
Published: 2021-01-25 01:13:04

### Ruby on Rails
I've made my way out of the Sinatra web app world and into Rails. For my first Rails app I decided to go with Ghostbusters.  To begin Rails makes life pretty simple.  all that is needed is to install the gem and type out rails new into your console.  This gets you started with a blank slate.  Click [Here](https://guides.rubyonrails.org/getting_started.html) to get all the info needed to start your own rails app.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/vxgddl8lr1ndstsqdymy.png)

### Ghostbusters on Rails
I chose to go with the busters because of the relationships that I needed to setup.  Has-many through and belongs to.  The busters are kinda like doctors in this way.  My users have many appointments and have many busters through their appointments.  Vice versa for the Ghostbusters.  Many users through their appointments.

### Making the App
After generating a blank slate I began to setup the app. Easily done by rails generate resource Ghostbuster.  This gives me a controller, view, model, and all the routes.  Along, with an empty migration, which is nice when you are only beginning to decide how to relate your models.
More info on Rails generators [Here](https://guides.rubyonrails.org/generators.html).  For me the first thing I like to do is get the relationships setup, see below.  After this I begin deciding a flow for the app (i.e. how I want my users to interact with it.).

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/34osf79pe8lwlnn02lqv.jpg)

### Routes
One of the amazing things that Rails does for you is setting up the routes.  After you use rails generate resource you can find your newly created routes in the config folder.  Start up the server by typing *rails s* into your console and go to the *listening on:* in your browser usually *localhost:3000* sometimes *[::1]:3000*, then type **/rails/info/routes** after that and you can see all the routes with their path shortcuts easily in the browser.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/d3cc3riwxm5ub0tzp7eb.jpg)

### Getting Logged In
This is very similar to Sinatra in the way that you use sessions to store a *user_id* after verifying with [bcrypt](https://github.com/codahale/bcrypt-ruby.git).  But, for this app I needed to have a third party log in.  I love Google and all of its googliness.  So I chose to use Google to log in with.  Now this wasn't so easy.  The first thing to do is to get a developer profile with google, and add the required gems into the app.  [Omniauth](https://github.com/omniauth/omniauth.git) and [Dotenv](https://github.com/bkeepers/dotenv.git) are a must.  You will need to create a project and add the allowed URI's to it.  Then you get a ID and secret for your project.  After putting the ID and secret into the env file your can setup the controller and route to handle the login request.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/mhrsjckwcp3u47tdazn9.jpg)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/mhrsjckwcp3u47tdazn9.jpg)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/mhrsjckwcp3u47tdazn9.jpg)

###Conclusion
There is so much that goes into making a web app and in keeping this short I will leave you with this. Rails is an amazing way to build out a new web app and makes it very flexible.  The gems that you include with your app make it so much like the web pages that you visit everyday.  You can see my app [Here](https://github.com/mpthor86/Ghostbusters-on-Rails.git).