
Dissecting Your Ruby on Rails Code; A Learning Practice for Beginners
What we can learn from the founder of Dell, Inc. on taking things apart
Michael Dell, the creator of DELL, was a prodigious learner. In NPR’s How I Built This, Michael explains the history of Dell, Inc. and how he first started to learn about computers.
The first computer he ever got, the Apple II, he took apart.

“One of the beautiful things about the Apple II, was that all of the circuits in the Apple II were discrete circuits that you could understand, so you could go in and start to play with those [components] and modify them and reprogram the bios and upgrade the system and take it apart and put it back together.”

Later, Michael speaks about getting his hands on the IBM PC. IBM introduced the IBM PC in 1981, and Michael — being fascinated with computers — promptly got it home and took it apart.
“How could you understand it if you don’t take it apart?”
He learned that this $3,000 machine was produced from parts that cost about $900. He would go on to build and sell upgrade packages for these computers, that would improve performance, before deciding to build his own computers.
Michael’s tinkering, dissecting, take-it-apart nature was what built Dell Labs.
“I wanted to understand it, and to understand it, you gotta take it apart.”
Moral of Michael’s story? To learn it, take it apart.
I’m learning to program in Ruby on Rails, and I’m doing every thing I can to immerse myself in the learning process; one of the methods I’m adopting is dissection.
Michael Dell used dissection to better understand computers, and to build a company worth billions. He’s not alone in using this method.
Leonardo da Vinci used dissection to better understand the human body, and to improve his artistic renderings of the human form.
Self-help blogger and Podcaster Tim Ferriss uses dissection to tease out habits of high performance.
Dissection is a highly effective method used by highly effective people.
This second part of this blog article is more for me than for you. I’m taking a part something I’m interested in learning about, and applying an additional layer of learning: “writing it down.” You should do the same. Read on if you’re curious to see how I dissected my subject.
Dissections comes from the latin word dissecare, which means “to cut to pieces.” So that’s what we’re going to do: cut this bit of Ruby Code to pieces. I’m going to take a couple of passes at the same code, restating the different elements in my own words and forming a meaning.
<% if params[:id] != nil %>
<% @url = '/user/' + params[:id] %>
<% if current_page?(@url) %>
<img src="/banner.png" class="profile-banner">
<% end %>
<% end %>
First Pass:
Statement 1: If A is not nothing, do something and call it “@url”.
Statement 2: If B, do something with “@url”.
Second Pass:
Statement 1: If params[:id] exists, create a variable “@url” that is equal to ‘/user/’ + params[:id]
Statement 2: If the first if statement checks out for the current page, display the image “/banner.png” with the class stylings “profile-banner”
Third Pass:
Statement 1: I want to display a certain banner with a certain user_id. I know that the profile page URL contains the user_id. I set this up in my routes.rb file previously
get '/user/:id' => 'pages#profile'
So my first IF statement says that as long as the :id is there, grab that :id, join it with the text string “/user/”, and then save it as a variable “@url”.
<% if params[:id] != nil %>
<% @url = '/user/' + params[:id] %>
Statement 2: If the current page is equal to “@url” (which is equal to /user/id), which looks like this:
http://localhost:3000/user/david
“david” being the user_id, then show the image.
The whole statement together:
<% if params[:id] != nil %>
<% @url = '/user/' + params[:id] %>
<% if current_page?(@url) %>
<img src="/banner.png" class="profile-banner">
<% end %>
<% end %>
This whole IF Statement is a way of saying “if you are on the profile page, show the large banner image.” We teased out whether or not we are on the profile page by asking if the URL structure looked like the same URL structure that we associated with the profile page view, and profile method, in our routes.rb file.