DEV Community

Cover image for Ghostbusters on Rails
Michael Thornton
Michael Thornton

Posted on

Ghostbusters on Rails

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 to get all the info needed to start your own rails app.

Alt Text

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. 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

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

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. 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 and Dotenv 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
Alt Text
Alt Text

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.

Top comments (0)