More Fun from the Trenches

Posted August 13, 2009

Another real-world example of Ruby and Rails sucking - check out these 2 lines in a Markaby file:

    text command.description
    
    unless session[:criteria_errors].nil? && !command.promo_applied
      unless session[:criteria_errors][command.id].nil?
        # ...

Explain to me how we get this error:

undefined method `[]' for nil:NilClass

On line #6 of app/views/order/_command.mab

    3:     text command.description
    4:     
    5:     unless session[:criteria_errors].nil? && !command.promo_applied
    6:       unless session[:criteria_errors][command.id].nil?
    7:         unless session[:criteria_errors][command.id].empty?
    8:           div do
    9:             session[:criteria_errors][command.id].each do | error_msg |

I don't see it. We already know the variable "command" is not nil, because we used it on line #3 to display text, and line #5 to check a flag. We also know "session[:criteria_errors]" has a value because we expressed check it for a nil value on line #5. So how does Ruby and Rails decide that it's suddenly a NilClass?

Comments

Displaying 1 comment

Add comment

More Ruby and Rails Haters

Not everyone gets sucked into the hype of Ruby and Rails - here's some bashers, and some with very valid points.

nathan.crause.name

blog.taragana.com

cbcg.net

www.webdesignforums.net

glyphobet.net

toometa.com

discuss.joelonsoftware.com

www.sambal.org

www.cftopper.com

www.straw-dogs.co.uk

www.javalobby.org