Ruby On Rails


Beginning Ruby On Rails E-Commerce
From Novice to Professional
by Christian Hellsten and Jarkko Laine
published by: Apress

Book Site | Sample Chapter | Table of Contents

I got this book to review and set it on the shelf for a few months… by the time I got to it Rails was up til version 1.2 and this seems to be written for version 1.1.2 – DOH! I tried a few examples and wasn’t compiling. After a little investigation there are only a few differences that would hinder this book from working with Rails 1.2. Namely, the assert_select has replaced assert_tag. That being said, this book is still great and applicable to Rails today. If you think about it, with as fast as Rails as grown it is impossible to keep 100% up to date!

This book is totally fantastic for beginners – because it actually shows Test Driven Development. What you say? Most books say something like that “to keep code size down, tests and error checking have been left for an exercise to the reader” … Riiiiiiiiiiight. How are you going to teach people coding that way? Tests should just be an automatic task of a programmer. Write some test… write some code. I honestly can’t imagine anymore how you could code anyways without them!

Not only does this book cover testing (including acceptance testing with selenium in later chapters – whoo hoo!) it starts out with not using scaffolding. I think, and this happened to me, at first I used scaffolding for everything and didn’t really understand the process. The book first goes through the “scaffold process” by hand, writing each method and view – after writing the test. Very cool. Then it tells you how to use scaffolding for the next model in the sample application. Awesome.

It talks about common concepts for really any site – tagging, adding forum, adding a form to upload images, browsing a list of products, multiple language support. Even if you are not selling anything on your site, you will still find this book extremely helpful.

Impress your friends! Learn how to write a DSL for testing. This is cool stuff, DSLs fascinate me to no end. Any and all mentions of it I study intently. Rails is in a way, a DSL for web applications!

Being true to the title “e-commerce” it actually talks about how to do payments over the web. Most books who talk about shopping carts skip that important step!

When you are ready to make your millions on the web there is quite an extensive chapter on deploying your site. It talks about LightTPD, capastrano, caching, and security! Its really nice to have all this in a book, instead of constantly looking online for documentation

My only complaint is – it doesn’t specifically mention what version of rails it used, I assume from the output of script/about that is 1.1.2 … and they should of talked about how to check out a particular version of Rails, just in case you wanted to use the exact version that is used in the book. Which may not be a bad idea for new users.

Well — anyone who knows me know that I love ruby… and perl next, and PHP comes in last of my favorite development languages. So of course when mom needed a website for her Bakery, I was going to do it in Ruby! I spent time getting my environment setup… threw it in subversion… setup a staging area on my server.. got some verbage, some photos and then finaly ready to hammer out the code.

I needed about 10 or so pages and an image gallery that would be easy to post photos to. I did a site a few years ago with Rails and file_column plugin and it was fantastic. I did it in 2 days and it was wonderful.

I am not quite sure what the problem was but I couldn’t get file_column to work for nothing! .. so I tried acts_as_attachment… no luck there either. i was using rails 1.2.2 on live and staging… i searched and searched on the errors I was having and no luck! PHOOOOOOOOEEEEYY! I decided to just use Dreamweaver Templates (which actually are quite nice for small sites if you want to avoid programming) and make a static site… to get at least SOMETHING UP!

I decided to use PHP’s Gallery to store photos, at least for the admin side. I had used it before and it has a fantastic java app called Gallery Remote that you run on your PC to upload photos. That’s easy. Then for some reason I thought – hey wonder whats up with Drupal? I went … I looked… hmm. So I downloaded it to my localhost and installed. Very nice! So I put it up on my moms site and configured it, added a module to connect to gallery — and within 2 days I was done. Sure I needed a few more little things, but that was way more then I could ever hope to accomplish with my homegrown site in rails.

So rails, I’m a little miffed at you. i wonder, are there too many cooks in the kitchen? are you getting kinda too big too fast? or am I just lazy and didn’t want to write a file upload, image resizing code myself? I didn’t use scaffolding for some parts and did TDD as I went along! I dunno…

I’ve always liked the Gallery codebase, its fantastic and Drupal as well. I’ve used and developed custom code for both. With good codebases, PHP doesn’t seem so bad. I might actually see if I can contribute to those projects.

I’m not saying that Rails == Drupal … using Rails would have certainly been more coding on my part, but the end result is about the same. What I wanted to do with Rails, Drupal had most of it done for me.

BTW, if you want to see the bakery site, check it out. We have a new logo and color scheme in the works!

For one of my projects, my layout includes optional sidebars on either side. I want to design this without tables.. so at first I thought something like this:

RUBY:
  1. <div id="leftside">
  2. <%= render :partial => "left_#{@controller.action_name}" %>
  3. </div>
  4. <div id="rightside">
  5. <%= render :partial => "right_#{@controller.action_name}" %>
  6. </div>

SO for index page, it will render the partials _left_index.rhtml and _right_index.rhtml ... but say if you don't want a side bar, then it can't find one... and you get an error. I would like to not have to resort to setting variables @left_sidebar =true @right_sidebar = false and have to do something like this:

RUBY:
  1. <% if @rightsidbar_on %>
  2. <div id="rightside">
  3. <%= render :partial => "right_#{@controller.action_name}" %>
  4. </div>
  5. <% end %>

Ideally I'd like a render_if_exist but I don't see anything like that in rails. Ideas??

Update

Almost as soon as I finished the post and sent to my friend Peter.. I decide to google for "render_partial_if_exists" and found this blog posting by Jeremy Hubert -- the exact solution! Peter was also in the process of adding a comment at the same time telling me with nearly the same solution. -- Check out Jeremys post, its awesome.

As some people plan vacations, I'm planning a Ruby weekend.

Today Friday, I'm going to get my day job projects worked on so I don't have to do any on the weekend, do any errands and other things today and clear the weekend! I will be working on a site for my mother's new Bakery/Coffeeshop! Save for going to the gym every day for a while, church on sunday and visiting with family on monday, I'm going to see how much I can get done in 3 days.

I'm always excited to see company's blogging about their progress, especially with development. I happened to see this post on the ROR Blog about Revolution Health. And here is their blog. Has some interesting things about their progress with Rails. Also, a friend of mine, Peter Harkins is starting his own company and is blogging about how he is using rails -- good tips to be had there also.

In addition to companies, I also like to follow independent consultants like Obie Fernandez, who is starting his own consulting company and is posting some interesting tips along the way.

Its companies and people like this that inspire me to work on extra projects, and I'll be keeping my eye open this weekend for any neat trick I discover on my "ruby vacation."

I've been trying for some time to get a Debian machine configured with Ruby and Rails. I always had problems with ruby-zlib! I tried building from source... finding a package... doing this and that, standing on my head, whatever .. and finally I found this blog that gave step by step instructions on installing Rails on Debian.

Rolling with Ruby on Rails ... got the green light on converting an existing PHP project to Ruby On Rails. I wrote a bit about it on CodeSnipers.com ... I'm not actually rolling yetl...waiting on getting the server configured. Hmm, guess I'll need to get a new blog soon if I have no more php to do? ... I think, will I miss PHP? .. course I'm also learning Perl and Python.

Speaking of Python, I'm going to go crash the Python meeting tonight -- they are talking about testing Django with Selenium ... and I dig testing so it should be fun. I've found that of all the mailing lists for the groups in Chicago, the Python guys have the most fun.

I've been reading Intermediate Perl which brian d foy gave to me (he's a nice guy). It's really good, I can't seem to get into a book unless its an O'Reilly Book. So I've been doing a few little perl scripts.

I need a new template for the blog.. this green thing kinda sucks...for me anyways.

I seem to have borked my kubuntu install, in deperate attempts to get my cingular broadband cell card working in my laptop, i did some install/uninstall of some pcmcia things and now it won't boot properly. Grrrrrrrrrrrrrrr. I did finally get it to recognize the card though.. sigh.. I keep remembering the words my dad says "Never give up! Never Surrender!!"

I have recently got on IRC. I've been on the #rubyonrails for a few days. I, a rails noob, has even managed to help a few other noobs. One problem I helped with, seems to have something to do with strange characters in your file, you get some strange error about \34 character (or something really weird) -- I found it by pasting my code into windows notepad and finding some strange unprintable character. I had copy/pasted I think some content from word (smacks head).

I'm starting to learn enough RoR to no longer feel like a poser at the next ruby meeting...which by the way, Jim Weirich, creator of Rake is going to speak... and... I also found a podcast yesterday with him.... AND one about Selenium (whoo hoo!):

Jim Weircih, Ruby on Rails Podcast (mp3)

QA Podcast - Selenium

I also got the pleasure of meeting (over IM) Ian Langworth, author of Perl Testing - A Developers Notebook. Andy Lester hooked us up in group IM chat. Very cool. :)

Pretty cool...

Apparently, "quote" is a reserved word. I had a database field with that name. I was getting a strange error ...

wrong number of arguments(2 for 0)

HUH? RoR is keeping score on me? who's winning??

Upon searching google, I found this post..

http://www.beyondthetype.com/rails/2005/11/27/rails-gotcha-wrong-number-of-arguments2-for-0

hmm.. so I checked the lis of reserved words...

Rails Doc on this: http://dev.rubyonrails.org/ticket/3628

SO let that be a lesson kids..

I was a bit alarmed (thats what happens before Cup of Coffee #2 to read this post:

WebObjects VS. Ruby

I hadn't thought of some of those things before. I have wondered though, what things would a paranoid security person have to say about Rails. So I posted to a RoR mailing list to see what they thought (forgive the ill named initial post, another side affect of doing something before Cup of Coffee #2)

http://www.ruby-forum.com/topic/54867#new

I've come to the conclusion that RoR would be no more insecure than using PHP and blindly using the _GET and _POST variables without validating them first.

I do not know anything about Ruby's taint mode and why its not turned on in Rails (not that I'm blaming Rails authors for anything) and the Rails developers may have made the decision to leave it up to the programmers.

[ RANT ]
Programmers need to take responsibility and not blame frameworks for insecure code, especially if the programmer can go look at the code for themselves. I've heard people bellyache about PEAR classes not checking input. Well, thats the programmers job and PEAR doesn't claim to do stuff like that either! What moron would pass code to code she or he didn't write without first checking the variables? Unfortunately, probably alot. But I'm not one of them and I'm not goint to sit around a gripe about it either.
[ /RANT ]

UPDATE!
Found some docs:
Securing your Rails application

Finally got RoR working on my laptop, I don't know how it worked before then stopped, but if I put use a user with no password it works fine. Something with the drivers I think for MySQL. But no matter, it works. I got subversion to work on my new webhost RailsPlayground.com and everythins is awesome! I can work on my laptop.. get home.. check in... check out on site. Awesome. I'm very happy.

« Previous PageNext Page »