Tuesday, March 22, 2011

Swear to blog

I just finished up the Blog tutorial I've been working on the last few days. It was clear, easy to understand and a great introduction to views, models and controllers, as well as building a functional Ruby on Rails application.

I know people always go on and on about how easy Ruby is and I'm starting to see why. I still don't have a grasp on writing my own code, but I get why something is done. I feel like I've got a good understanding of the basics, which is absolutely important for proceeding.

I'm also amazed at how easy it is to add new functionality to an existing program. Initially I built the blog and was able to create, view and destroy posts. Then I went back and added comments with the ability to create and destroy them as well. THEN I went back and added tags.

So I'm getting it. I've gotten over feeling overwhelmed (to be fair, I got over that a while ago) and I just feel excited about learning. More coding!

I think my next step will be to return to Beginning Ruby and skip over chapter 13 altogether. I'll probably read through it for reference, but it used MySQL a lot and I really got hung up on that crap for a while. Still, that book has been a great resource and finishing it up will be worthwhile.

Monday, March 21, 2011

Rails work, refactoring and Frankensteining

Still working on the blog app. Today I created a new model for comments and went through tying it to posts, then editing the code to make use of partials. Using partials in this way seems to fit better with Ruby than writing a laborious chunk of code.

So here's the original code:


And this bit is going in with the rest of the code that displays posts, so it's feeling crowded. But then I split it off into a partial, which I'll call with a much slimmer bit of code.

Then here's the partial:


It's basically the same code as before, but it's been sectioned off and put into the views directory. Now it can be called like so:


Look at that tiny little code! And all it took was a little refactoring and reorganizing and that bit of code for the view is easier to read and understand, and the partial is easier to access in case it needs to be edited later.

This method of pulling a bit of code from another file reminds me of the scraps of php I used to use back in the day. Ruby's kind of the Frankenstein of coding languages, anyway, right? But it only used the good parts!

Sunday, March 20, 2011

More beginning Rails work

I'm still working through the beginning Rails tutorial, creating my VERY OWN BLOG. This tutorial has been incredibly helpful and everything I've been instructed to do has both worked on the first try and made complete sense. I've got a better understanding of HOW Rails works on a server. Here are some questions about that, however.

Say I create an application, test it on a local server and everything is fine and I'm ready to put it on a web server. Does the code need further editing, to tie it to a web server, or does it work automagically?

It's my understanding SQLite is fine for smaller web apps, but if I thought the application would have wider appeal, is this the point I'd have to edit the code to work with MySQL? Maybe I'm getting ahead of myself. (Again)

I feel like another piece of the puzzle fell into place today. I've always wondered HOW Ruby does what it does on the web, and Rails is the answer. Then I'd wondered how Rails worked and this MARVELOUS tutorial is really shedding some light on the question. This tutorial is also good at demonstrating how and when you create and edit functionality.

It's refreshing to be working on something different, too. Beginning Ruby has been a great resource and I'll definitely come back and work on some more projects, but I was really getting frustrated due to my problems installing MySQL and my foolish insistence on following the book TO THE LETTER.