ruby on rails

Beginning Ruby

by Suw on June 11, 2007

So a few months ago I thought that it would probably be a really smart move for me to join LRUG – the London Ruby Users Group – so that I would be able to meet some other Ruby users, and maybe find some help in my quest to learn Ruby on Rails. It's been a bit intimidating, I must admit, as there are a lot of people here who actually know something about Ruby and RoR, so I feel a bit overwhelmed at times. But that said, I'm getting to know people and have found someone to mentor me and help me get (re-)started on RoR.
About two months ago, Apress Books offered a number of copies of Beginning Ruby by Peter Cooper to LRUG members in return for a review. I thought that it would be a good thing for me to get a copy and try to get my head round Ruby as a language, instead of trying to just absorb it osmotically by doing stuff with Rails. Apress very kindly gave me a copy, and two months later I can safely say that it looks really pretty on my bookshelf.
*cough*
I'm currently sitting in the LRUG meeting and have successfully had my guilt strings tugged by Murray Steele, so I have downloaded Chapter One, which is available as a free sample and I promise that I will read it and write a review of it before the next LRUG. I absolutely promise, cross my heart, hope to get a small but irritating blister on my little toe.

{ Comments on this entry are closed }

Typo, typo, how I love thee

by Suw on December 29, 2006

I haven't had a chance to look at my Ruby on Rails for a few weeks, but finally on Wednesday I had a few hours to play with it. I had left my charger in the suitcase that Kevin had by his desk at work, though, so my window of opportunity would last only as long as my battery.
The last time I worked on my RoR, I ended up with an unexpected result. The book I'm working through, Agile Web Development with Rails, has you make a web shop, and I'd got to the bit where I was implementing the shopping cart function. I went through a ton of coding, but when it came time to test I got an unexpected result – the shop page failed to show any products, just the 'Show my cart' link. I was expecting to see a list of products with the 'Show my cart' link at the bottom.
I ran out of time and had to leave it, but coming back to it this time round, it still wasn't clear what the problem was. The book's publishers provide you with a bunch of files that show you what the code should look like at each stage of development. Now, I could cut and paste the code, but I don't because that way I wouldn't learn anything. Instead, I type it in from the book, and use the source files as a reference in the event of anything going wrong. Of course, things go wrong regularly, because there is always a typo somewhere.
I sat and pored over the code, file by file, line by line. Fixed a couple of typos, but neither of them actually fixed the problem (although I'm sure they fixed other problems that had yet to manifest themselves). I was starting to feel really frustrated, as my battery was not going to last long, and I wanted to actually make progress, not just hit my head against a brick wall for two hours.
I compared the code to the code in the source files, and to the code in the book, but still nothing. Then, going back step by step over what I had done, I noticed one little action taken in Terminal (i.e. at the command line):
drop table if exists line_items;
create table line_items […]

D'oh! This command deletes the old table called 'line_items' if it exists and replaces it with a new, empty one. Suddenly, a moment of clarity: the store front wasn't displaying the products because I had deleted them all! In fact, there's even a footnote on page 85 which says “If you don't see a list of products, you'll need to go back to the administration section of the application and add some.”
Oh dear. Note to self: Read the footnotes.
Anyway, progress after that was good, despite further typos. I made it all the way to the end of Chapter 8, and this afternoon I'm going to have a stab at Chapter 9. I'm still really just doing what I'm told in the book, but patterns of meaning are starting to coalesce out in my mind. I'm not sure I could yet create an application from first principles, but I'm starting to generalise out rules from what I'm doing which will, in due course, give me my much needed first principles.
Besides all that, it's actually a lot of fun. I can't wait til I have a bit more time on my hands to work on this more regularly.

{ Comments on this entry are closed }

Fixed!

by Suw on October 16, 2006

Thanks to Matt for fixing what was up with my Ruby on Rails (for those of you who care about such things, it was a path issue, and some permissions that had gotten buggered). So now I'm working my way through Agile Web Development and making good progress. Feeling very happy about this! Lots to do before I can make my own app, though, but at least I can now forge ahead.
Not sure, though, whether to buy the Second Edition of the book I've got or stick with the first one to start with. I think I have enough to be going on with, without coughing up more cash. Although again, I'm noticing that the code samples given on the site aren't the same as the ones given in the book. I guess this must be a fairly common problem with these sorts of books.

{ Comments on this entry are closed }

Must. Stop. Hitting. Head. Against. Wall.

by Suw on October 9, 2006

Ok… so I hit a brick wall with my Ruby on Rails book, Agile Web Dev. with Rails, which was that MySQL didn't behave the way the book seems to say it should. So the book implies that one should be able to issue MySQL commands using Terminal, from the directory in which the Rails app resides. So let's say you create the example Rails app 'Depot', in a directory called 'Depot'. You should be able to, from the Depot> command line be able to make MySQL do things.
Except it doesn't.
I have managed now to get MySQL to work on its own, and decided that I obviously needed to get more familiar with it so Saturday I bought Teach Yourself MySQL in 10 Minutes by Chris Newmann. To start with, it looks fine. But when I came to installing the sample database, I hit another brick wall. For starters, it's not easy to find the right files to download from the Sam's Publishing site. Took quite a bit of ferreting about to find it. And secondly, the instructions given in the book for the installation of said database simply aren't clear enough and do not work for me.
Thankfully, a friend of mine is helping me via AIM. But it's just frustrating because I'm not stupid, and I have enough of a programming background that I understand the concepts, but don't have enough experience to fix the problems that are stopping me learning, erm, how to fix such problems.
Later…
It seems that the author has made one too many assumptions, and has omitted a few vital steps in the process to get the sample tables (note: not database… they didn't say 'make this database first, then import the tables', which would have given me a clue as to why their commands didn't work) up and running. Now, you'd think that if you're writing a book for beginners you'd actually start at the beginning… This is when wikifying a book and letting people add in the missing steps would be a Really Good Thing.
UPDATE: Turns out that isn't the only issue with this book. Whilst it's a minor nit, it's annoying that some of the values stated in the book for things like column names aren't the same as those used in the sample database. So it says I need to 'SELECT id, first_name, last_name', but it turns out that there's no column called 'id', it's called 'contact_id' instead. OK, so I've learnt to find out what the column names are, so this is not holding me back, but it's poor that there isn't consistency between book and code.

{ Comments on this entry are closed }

SHiFT: Ruby on Rails

by Suw on September 30, 2006

Josh Sierres is giving a workshop on Ruby on Rails so I'm going to take notes more for my own benefit than for yours.
So, what's the big deal about Rails?
Most important point is that it gets out of your way. Lots of people refer to it as a boring framework because the people who start using it in real business apps find it gives them more time to focus on business logic and less time on implementation details.
Productivity. Gains are massive. Not necessary to put a number on it because it's not measurable.
Happiness. Productivity makes people happy, and happy people are productive. Very important point. Rails programmers have a little smirk on their face because things start working better.
Creativity. Lots of people from design and usability are now using rails as their gateway into implementing tings, getting things prototyped without depending on a programmers. Designers can do this, without knowing Ruby at all, and can build an entire app in a few weeks, and do the design themselves.
Lots of plug-ins, lots of people contributing, nice atmosphere in the community, and a lack of tension.
'Bad things', that stop people using it. Rails is not a silver bullet. Anyone who says one tools solves all problems is a salesman.
Ruby is a slow language. So people say 'does it scale?'. Yes. Share-nothing always scales, i.e. the type of architecture where you have no shared resources between instances of the application (see Cal's book about scaling Flickr). These always scale. But you have to have the right people to build them. So pointless to talk about scaling really.
Some e.g.s: 37 Signals, MOG, Robot Co-Op.
Few experts, but you only need one.
Rails is not ready for The Enterprise. It's missing internationalisation, composite foreign keys in the database natively, etc. But Ruby's a very powerful language and people can write plug-ins and add behaviour without getting in the way of the user, so there are plugins for both these and other issues.
But is The Enterprise ready for Rails? It comes with its own philosophy…
But…. all this doesn't matter. Rails is good for most web apps – most people most of the time will get what they need to get done quicker with Rails.
Risk. Use risk inherent in switching to a new technology, Rails, to make yourself more valuable. Can easily demonstrate new projects in Rails.
Opposite of risk is not safety, it's stagnation.
Rails is:
– a tool for getting stuff done faster
– maturing very quickly, more and more programmers using it
– sneaking its way into all types of businesses
– supportive of AJAX, Agile development, and other buzzwords
Rails has an edge because
– AJAX functionality is in Rails in a way that puts it into Ruby itself
– uses one language for everything
– gives you the ability to create natural language mini-framework on Ruby
And it creates happy programmers.
Rails does not stop you needing to understand HTML or SQL, but it reduces your dependance on repetition. So gives you tools to make your HTML cleaner, or writing SQL for basic queries.
It's not a high level set of components like user authentication or shopping carts. Push back against this type of components, because there are so many ways of implementing business logic, like log-in or shopping carts, that it is bad to force one way on people by creating these sorts of components.
It's not magic, but it feels like it for a while.
Power of Rails comes from the Ruby language.
More about rails…
It's an Models, Views and Controllers framework. The Model is how is should work, the View creates the thing you look at and the Controller joins those two together.
Can override conventions, but best not to otherwise you'll not get the productivity gains. Can automatically create views and controllers.
It lets you test everything inside your Rails app, with very few exceptions. Building these tests gives you a sense of security and a way to mitigate the risk in your app to prove that it works without troublesome too and fro with browser.
A few ways to get started. Can build out your database first, then build the app around it, or you can generate database files and create a 'migration' which controls the changes you make to the database.
(Had to break off here and go to a session I'd promised to be in.)

{ Comments on this entry are closed }

I just do what they tell me to

by Suw on September 27, 2006

So whilst I was at EuroOSCON, I had a chat with a few people about an idea for a website I have. Well, not really a website, more of a web app. One person I chatted to was Rob McKinnon, who managed to convince me that I could do the whole thing myself in Ruby on Rails. I explained how my programming skills are, in general, sub-incompetant, but he convinced me that I'm qualified enough to play with Rails and that I might even actually be over-qualified.
I'm not really sure I believe that. I mean, sure, yeah, I used to tinker with Perl, Python, JavaScript, (and, way back when, Basic), but whilst I could adapt other people's work, I could never write anything from scratch myself. Tinkering is, of course, where you start when you're learning how to code (which is one reason why software patents are such a stupendously bad idea, but that's another discussion), but there are important steps that come after tinkering, including sucessfully sticking together chunks of stuff you've got from other people, and finally, being able to create new, original scripts. I never really got that far up the learning curve. (Actually, to be honest, I stood well back from the learning curve and thought 'Oh, my, that looks a bit steep…')
So now I've decided that my web app is going to be my baby. I am going to code it, as much as I can. I'm going to learn Ruby on Rails, and whatever chunks of MySQL and CSS and whatever else I need to get a prototype web app up and running.
There will be confusion, yes. In fact, there already has been confusion, within about the first five minutes. Thanks Matt, for introducing me to Locomotive and helping me get started. Now, sitting on a plane to Lisbon, there is further confusion, but I'll have to wait til I land to sort that out, which is annoying because I thought I was doing really well.
There will be frustration. Again, actually, there already is frustration, but it's healthy. It's making me want to work harder on this, not give up, so that's ok.
There will be cursing and screaming and pulling of hair (mine, I hope, not anyone else's). This may actually be entertaining for you if you enjoy that sort of thing, so I'm considering selling tickets.
And eventually, there will be success.
Meantime, however, I have Agile Web Development with Rails, by Dave Thomas and David Heinemeier Hansson and I have already worked my way through creating my first 'Hello World' app. It was easy. Once I got Locomotive going, and was accessing the right version of Ruby, all I really had to do was do what they told me to in the book. That's not just easy, it's easypeasy.
Now I have a MySQL hiccup to get over, but once that's sorted I'll be away working on their example shopping cart web app. I'm already designing my tables and thinking about how my own app is going to work, and am eager to start actually playing with that, but until I have MySQL working properly, I am slightly stuck.
I will keep you up to date on my development.
Pun intended.

{ Comments on this entry are closed }