Views in Rails, not a tutorial

I have been continuing my journey in the contract lane for the time being. What this is giving me is an experience in programming aspects I have not been exposed to before. And what I am very appreciative of is the patience the lead engineer has shown, especially based on how much I still have to learn. One of the things I have picked up on is the “view” portion within Rails.

What I am accustomed to is rendering inside of my controller methods. This could have been much easier for the program I was in to teach, as our cohort was already fast-paced, we had minimal time to spend learning full CRUD actions on the backend.

At my current contract, I sent in my controller with my render inside my controller and was told to change it after a review. I had never seen it before and was referred to a view for another model that had already been set up. What I learned was that an index method will automatically look in the views for an index render, so nothing would need to be called after you set your index. This is also true for a “show” method.

Keep in mind I also did this using the JBuilder gem. What is needed in your view is a folder named after your model, and files named index or show.json.jbuilder. Within those files, you will refer to your partial folder inside of your views labeled _modelName.json.jbuilder. I have a general idea of how this works; however, I don't have a strong enough grasp to explain what is going on in the jbuilder files. I will be reviewing jbuilder documentation in hopes of putting a post out that will explain this step by step next week.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store