Archive for Ruby On Rails

Is Rails suffering the same problems as PHP?

I know that mentioning Rails and PHP in the same sentence is taboo and can incite many flame wars. But hear me out — Some say one of the “downfalls” of PHP is that its so easy to write applications and just about anybody can write a PHP if they put their mind to it and learn the syntax. As a result, PHP Applications have a long history of badly written, insecure code and has really been shunned by many advanced developers (aside from many poorly named methods, I think PHP is alright!).

In recent months I’ve been recruiting for a Rails Developer at my company, in Chicago. I did a phone interview and the guy couldn’t name me any rails sites he reads, or name the 7 rest actions, or even tell me what version(s) he uses. Now, I’m not claiming to be an expert, but I would think that even an average Rails developer would know that.

I’ve also seen code where the developer doesn’t quite get MVC. You don’t need to be validating values in your controller and adding error messages to @model.errors.add for example. You don’t need to be setting up display labels in your model. You don’t need to be counting things in a helper method. I was thinking, why is it so hard? Is it because in mostlanguages we have had free reign to interpret MVC however we pleased? I know I spent many years in PHP trying to develop a DAO. I made an object that returned a row of data, with methods to access the fields. But what about a collection? what is that? I experimented with an array of objects but I felt that was too wasteful. Iexperimented with a DaoSet that was made to hold a collection — complete with iterators! I even struggled with MVC and knowing what went where…when I saw Rails it was like someone who met their true love — this is it!

After experiencing Rails, I realized hey I can do some of this in PHP! I wrote a simple MVC framework in PHP. I called it StupidlyEasyMVC Framework. I was able to use it at work (at the time, I was still at a PHP job. Some say I talk about that time in my life as if it were a prison sentence haha). SO I was able to apply things I learned from Rails, into an existing structure at work. Just like the guy from CDBaby — I couldn’t drop my existing PHP site and just start converting to Rails, but by starting to gradually switch from what I had to an MVC structure, it made my code cleaner and easier to work with.

So as I look for advanced rails developers, I find they are far and few between. Either they are hotshot consultants or working on their own startup. What makes a rails programmer “get it” and really work with the framework instead of against it - still trying to write as they always have?

Here are some things you can do if you feel you are still writing PHP or .NET code in rails..

Get a project. You can read and dabble all you want, but if you don’t have a project, you won’t be forced to learn. Along with that, you need a timeline to force you to keep at it!

Watch all the Peepcodes! especially the REST and rspec episodes. I’ve search hard and long enough for answers, to find comprehensive training in ONE spot, in such an easy to learn format is awesome. I constantly talk about peepcode and I won’t work with anyone who hasn’t watch them.

Peepcode Code Review - their first book, full of helpful hints and gotchas that will really help you move beyond a beginning developer

Ruby Inside Blog - www.rubyinside.com

Jay Fields - http://blog.jayfields.com/

Obie Fernandez - obiefernandez.com

Books:
Agile Web Development with Rails - If you are doing Rails and don’t have this book, get it! It is the bible of rails! I don’t care if you have the first edition already, this will save you time!
The Ruby Way by Hal Fulton - because if you don’t know ruby, you will never be a good rails developer.
The Rails Way by Obie Fernandez - its good because I tech edited it before publication! It is a comprehensive instructional and reference book — all in one. I cannot wait to get my hands on a paper copy of this to keep at home and one for work. (just got one this week…I’m ecstatic)

Well this has been mostly a rant but hopefully a help resource to move into more advanced development of rails. If you have other insights into this problem or suggestions for how to improve, please leave a comment!

Comments (3)

Rails Potluck

Its been a while since my last post! Been so busy working on ruby, at work, at home and play. Some of the interesting things I’ve been doing recently:

Conductors - I’ve been fascinated by the Presenter Design Pattern posted by Jay Fields and more here and read up everything I could, still it wasn’t quite what I wanted. Then I found the blog entry by New Bamboo Conductors and Presenters. Basically a conductor goes between model and controller whereas a presenter goes between a view and model. A conductor is what I’ve been wanting — a way to group to associated models such as customer and an order and work with it as one. I can call save on it,I can pass it to a form builder (which is sort of present-y but I don’t care) Anyways, I am working on a blog post about it.

Exporting data to fixtures - for one project, I wanted to extract a subset of data to fixtures so I can load into a staging site for testing. Say I wanted to take the most recent 100 orders, which also grabs the associated record from customers, addresses, invoices, customer categories and products table. With the help of one of the recipes in the Rails Recipes (Pragmatic Programmers) I was able to write a rake task to export the data. The example exported all data from every table except schema_info. I rewrote it with explicitly naming the tables and the queries needed. I’ll write up something on this too, including how I got around my yaml array being TOO large(I think thats the prob anyways) to import! doh!

Admin interface - I used the restful_authentication plugin. That’s great for a sign up and login page but I also wanted a way to administer users. I debated on whether to make an controllers/admin/users_controller and banish anyone trying to access that controller and not an admin … or, I can add the CRUD methods to the controllers/users_controller and check for admin at the start of the CRUD actions that only admin can use. I turned to the wisdom of the DevChix mailing list (sorry boys) and got some good ideas from the Chix. I need to write this up as well!

Facebook App - Not Rails, but could be. I was recently contacted by someone to make a facebook app. I’ve never made one, so that night I set out with PHP to write a little app. Within a few hours, I had a simple app. I let the company know that I figured out how to do it, and what was the next steps in getting the contract? *poof* they never emailed me back. I think they figured — well if SHE can do it two hours, we can probably figure it out ourselves! haha… but it was fun anyways.

Rspec and Mocks - It took me awhile to get the hang of mocks… but determined I figured it out. Nice. :) Right now I am just using the mocks in rspec, but want to look at other mocking frameworks to see what the difference is.

Autotest and snarl/growl - I now use autotest all the time on all my projects. I saw on PeepCode that Geoffery used growl to make a small window pop up on his mac with the status of the last run test. I showed my husband and said SEE? I need a mac. I thought there must be a windoze thing that does the same thing, I searched and found this post on SourceCraft Blog where the author talks about setting up autotest with Snarl (for windoze). I tried my darnest to get it to work on windoze and popup a snarl message (like you cool mac kids with your growl notifications) .. and there’s a bug somewhere because it says every time 100% tests pass..and I know I’m not that good. Haven’t worked on it in awhile though, so I should try again I guess (or get a mac, which I am trying to do!)

rcov - one project I was working on went pretty fast (one danger of doing Rails for people that are used to “other” languages) and I was accused of not making quality code! so I installed rcov and showed them my 100% test coverage. I know rcov doesn’t tell you how “good” your code is, but it does tell you its well tested. How about them apples? ok, I’m a smartass sometimes. ;)

The Rails Way - I was one of the technical reviewers for “The Rails Way” written by Obie Fernandez. It was a fascinating read and I learned a ton. I can’t wait for the paper book to be printed, due out in October (The site says November, so maybe I am mistaken on October). If you do Rails — get the book! I’ll post a more detailed review when the book is out.

PeepCode.com - I’ve been an avid PeepCode.com fan from the first screencast I purchased — about REST. I watched the episodes on TDD and the two about RSpec. This was very helpful. See, one problem I find with learning rails stuff is that there are all sorts of blogs on something, and sure by picking up pieces here and there you COULD probably get the learning you would gain from PeepCode.. but with PeepCode, its all in one spot and you can SEE it works, which is key for me. There is alot to be said for “seeing” something work to solidify the process in your mind — but everyone learns different so that probably doesn’t work for everyone.

Watching the rails commits - Ok so maybe I need a life. I’ve been watching the rails commits every day and seeing what changed. Alot of clean up going on it looks like. One of these days (soon I hope), I’ll test some of the patches or try to fix a bug.

Lots of stuff going on and I’m having fun.

Comments

Nifty Rails Stuff

I’ve been kinda on a rails spree lately, I guess I’ve had some free time and also redoing a rails 1.1.6 project (and was noob then and no clue of what I was doing) and updating it to use REST.

I got Geoffrey Grosenbach PeepCode’s REST Tutorial, which is very awesome and well worth the 9 bucks. Its over an hour long! I also got the RJS Tutorial which is also awesome. I can’t wait till payday to get the $40 pack so I can get some more! There’s just something about SEEING something work that makes it stick sometimes.

Also I spent some time on Railscasts which features a ton of short demos on rails topics. Very cool. In particular i liked Testing Without Fixtures which is cool because sometimes fixtures are a PITA!

When watching one of the PeepCode screencasts I saw him using “autotest” .. a cool toy which I must have too! I searched for it and found this posting on his blog. Now I’m autotesting all the time :) It basically monitors your rails site and runs the test everytime you change your code.

I’ve been using e-TextEditor and slowly learning the shortcuts. I love the font that was on PeepCode’s screen cast and found a link on the PeepCode FAQ where I can download it. For Free! And it mentioned the name of the theme used in Textmate — which happened to be the one I had found in e-Text-Editor and was using. No wonder I liked it! I also used this font in my Putty settings and changed the awful default colors (esp that dark blue! hard to see!). e-TextEditor is in Beta but its in great shape and i was so happy to see a “close all tabs” feature put into the latest build. I’ll be ecstatic when they make a linux version.

Comments

A Lightbulb Just Went On

I was starting a redo of a old (rails 1.1.6) site and thought I’ll store the rails in the vendor directory so I don’t have to worry about what version is installed in the server, so I looked up this nifty Article on SitePoint where they explain how to do that. Installing and Managing Edge Rails.

I started with some basic steps to “redo” my old site.. used the controller generator.. whoa.. huh? “.html.erb” .. I instant messaged a friend, Carmelyne and said whats up with “.html.erb” .. she is like, oh thats edge rails. I thought I had installed 1.2 release instead but on closer inspection I did indeed install edge. I must have had the version number wrong or something. Doh, oh well.. let me try it anyways.

In further discussion.. she suggested i look at using REST.. “isn’t it just for webservices?” i ask, she said no. I’m not doing anything that I will need to publish web services for…. its just a bakery order site. But, I did a little research and Carmelyne pointed me to some resources…. and I got it!

A lightbulb went on!

I used the scaffold in edge to build my model… looked at the controller…looked at routes.rb … and i got it. :)

Read these to understand what the heck I am talking about:
A Series of 5 articles on REST and Rails - very basic and helped me understand how, what why of REST and Rails.
REST on Rails - another good one

I feel like I’ve been a bird with my head in the sand. I’d read stuff before but never understood how, what and why of REST.

More to follow as it sinks in.

Comments

Book Review: Beginning Ruby On Rails E-Commerce

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.

Comments

Get Er DONE!

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!

Comments

Optional Sidebars

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.

Comments

Ruby Weekend

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."

Comments

Soooooooooo Happy!

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.

Comments

I’m rolling

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!!"

Comments (1)