Adventures in Coding, Pt. 2

My last post about my coding adventures was destroyed by my negligence. Let’s hope this doesn’t suffer the same fate.

So last night, since I was able to work on the computer without a stormborn power outage, I fired up the second lesson of my Ruby on Rails class. The first lesson was centered around generating a new app, which led into a breakdown of all the bits and bobs of Ruby – gems, gemfile, some brief examples of code, all that stuff – as well as the essentials of uploading app frameworks to GitHub and Heroku.

The second one is building pages.

HTML and CSS, as I was telling someone, rely a lot on creating pages and stylesheets as if they are each different documents. Essentially, that doesn’t change with Ruby, but Ruby makes it a lot more convenient – and fast, I think. Whereas in HTML and CSS, I’d find myself opening a new document in Sublime Text, then editing it through that, and saving it as either .html or .css, Ruby has a command:

[current directory] $user generate controller Pages [name of page]

So, typing that into Terminal gives you a shiny, new, blank html page to work with. After editing the pages controller file in the database – changing definitions and actions so the app directs to the correct pages – you can have a url point to “home” rather than “home.html”.

This makes me grin. I don’t know why – exactly – but I had wondered why some pages allow that to work without a file extension, whereas others don’t. And it’s all through the power of Ruby. [Collective “Ooooh” and “aaaaah”]

Further, all the messing around with copying and pasting navigation bars, logos – well, everything that’s not the page-specific content, really – can be accessed using partials. Partials are bits of code that look like:

<%= render ‘[containing folder/filename (i.e. ‘header’)]’ %>

What that’s doing is telling the page to render a certain bit of code at a certain location, and spit that out on a page. You do that by putting the above code on a layout page, which controls the default view of every page.

Everything that’s not defaulted into a page is plopped into that layout by

<%= yield %>

From what I saw last night, that looks like it’s included by default when you generate a new page controller. But if you’re reading this, and you know that’s wrong. Let me know!

So, basically, all you have to do when you generate a new page is write in the HTML for the content of the page.

My God, it’s so easy!

(That said, I think I’ll still keep using <a href=”…”></a> for links. <%= link_to ‘…’ ‘…’> just feels wrong.)

Of course, there are the details to work out, like defining the pages and controllers, and all of that, but man. I get why people scoff at Ruby, but it seems like doing so would be like looking down on people for driving a car when they could be riding a horse. (Or flying across the country when they could be driving…)

So excited, you guys! Just wish I could rewatch these videos to hammer in the ideas, but nooOOoOOooOOooOOo. I should be working. Thanks, The Man.

Adventures in Coding, Pt 1

Oooooooh no.

I had a 700-word post drawn up in Word detailing my reasons for learning HTML, CSS, and Ruby on Rails and then, contrary to my belief that hitting Ctrl+C meant that I’d copied it all, it all went away. Into the aether.

I tried to paste it, was greeted with nothing, and went “Oh, no.”

So, the nitty gritty:

Learning HTML, CSS, and RoR because (apparently) it’s hard to get a job without some skills other than “I write good.” While I’m not great at these languages by any means (having just picked them up in April), I know enough about HTML and CSS to work up a website, can upload it to a web host, all that jazz.

“But Aaron,” you may say, “what about Javascript?” Well, that’s coming. My uncle, sent me a link to a series of YouTube videos on front-end development he made with some other dudes, and Javascript’s included in that – so Javascript’s a-comin. In the meantime, though, I received a coupon for a Ruby on Rails course at One Month Rails and figured now’s as good a time as any to pick it up.

So far it’s good, but mind-boggling. Any ideas why I can’t launch Sublime Text from Terminal, even though I type in the file path followed by “~bin/subl”? No? Ah well.

Anyway, it’s going well. Excited about it, and I’m looking forward to the upcoming lessons.

So much going on!