The Next Step Forward: Living in Rails
Here I stand overlooking the mountain on this house that I built. I see the valleys, the cliffs, the animals, and dangers. Now that I have passed it, looking from above, it all seems so tiny, insignificant. I look back on how I got here.
I started off learning some HTML, learning about tags, some constants, object-types and and how to make everything pretty with CSS.
From there React showed me how to make everything much more stream-lined and neat, it taught me about components, how to share information between components and the importance of organizing your files aka, “Separation of Concerns”.
From there I learned about Ruby. She was definitely an unfriendly beast at first. She bit and tore at me and her complexity with SQL seemed like it was going to be the death of me.
Then Active Record came in to save the day and make life much easier by stream-lining a very tedious and complicated process. This culminated into a API project which was powered by Sinatra.
That was when our finally contestant decided to rear their face: Rails. Rails, unlike the light-weight back end definitely had a great degree of momentum and power in her punches. She was fully capable of creating models, controllers, and routes as fast as you could press the “Enter key” through her “rails g”, (Rails generator). With her even being capable of creating all of these at once with her “rails g resource” the question was then, what more was there to it?
We created the model, the route, the migration files, and the controller, what more was there to build?
Well. Simply speaking, nothing. All you really needed to do after that was customize what the controllers were doing for the their CRUD operations, a run “rails db:migrate” and you could call it a day, your API would be a fully functioning. The house (the API) would be finally built…
But as we all know, having just a roof over a person’s head and being encased by four walls is hardly the only thing a person would want from a house. For starters one thing that most people (for some strange and unknown reason) care about, are the rooms in the house or more precisely the purposes and relationships of the rooms, aka the layout.
The relationships between models is an important way for individuals that plan to access the site to be easily oriented and not frustrated. Because, while one could have two models, a cat and an owner model which you access completely independently of each other it would be very frustrating and time-consuming. If instead you choose to put a door between the two with a has_many and belongs_to relationship, you could very easily communicate through the rooms when you wish to grab any bit of information.
But, what’s missing here? What very important part of any door worth a cent have we not mentioned?
One of the most important things that I learned about Rails was about authentication, and authorization.
Authentication is simply asking who the person is, it would be the equivalent of looking through the peephole in a door.
While authorization is only allowing the users with the proper credentials inside, or only allowing those with the right key through certain doors.
These two processes were accomplished through the users model, and controller, and the sessions controllers.
One could only receive any authentication by showing up to receive a key (They would have to “signup”). After the authentication was complete then one would be given the key (a session). This would allow them authorization to go to any of their specific rooms and change the layout of the room in whatever way they wanted (even putting up embarrassing photos or leaving journals full of their steamy fanfics).
Once they left, (their session ends possibly because they got “logged out”), the only way they would be allowed back in is by putting in the right key back into the door(by inputting the correct information and “logging in”) anyone else would not be able to enter the room unless they exact key to the room.
It is all this information along with various error handling methods that I now have under my tool belt which is just laying there on the counter top.
The wind outside looks really cold. The animals look even more vicious. This house is really comfortable. But it’s going to be fine. I been through worse. Let’s go.
Let’s go climb another mountain, let’s build more houses.
Thank you for listening.
Please be happier.
This has been Aeco, logging off.