Sunday, April 09, 2006

Playing with Ruby on Rails











# modified this to get the price as a decimal

require "bigdecimal"
require "bigdecimal/util.rb"


def price
    # we want to make Price a BigDecimal, the format
    # will look weird if we don't do anything to it
    # but we are using sprintf() in our fmt_currency
    # method, which handles this nicely
    BigDecimal(price_before_type_cast, 2)




Submit to Reddit


  1. Anonymous12:53 am

    elsif came from Perl.

  2. Anonymous5:56 am

    Elsif threw you off? Perl has elsif, Python has elif..

  3. Aargh ... must be showing my non-web background then. ;)

    FYI, the languages I DO know are:
    * VB
    * VB.Net
    * VBA
    * VB Script
    * LotusScript
    * Javascript
    * XSLT
    * Java
    * PHP
    * Omnis7
    * CSS

  4. Anonymous12:38 pm

    I think you are just showing your self-admitted spotty programming background. Ada also uses elsif and Perl has been and is very popular for other tasks before people started using it for web apps. Same with Python. It's bad form to rant about something that (a) you know little about and (b) is relatively common.

  5. Well ... it wasn't really much of a rant, the point was to perhaps help some other Ruby newbie out.

    I felt that it would have been nice if the Ruby book had made it more obvious, but perhaps it seemed obvious to the author that Ruby learners would come from a Python/Perl/Ada background?






    To get a better understanding of this beautiful way of life, please visit our blog Understanding Islam--->

    We hope to see there, peace

  7. "Admin", your screenname is a bit deceptive, however I appreciate that your doing what seems best to you.

    In the interest of tolerance I will leave the above comment as it stands, but perhaps you should have chosen a blog post where it was more relevant?

    You might also want to consider that like Christianity, Islam has many diverse interpretations. Even when you believe your current understanding to be the "only" way, I believe it is always best to let people know that you represent only one point of view.

  8. Anonymous11:07 am

    I agree that, despite what our anonymous friends say, it wasn't much of a rant -- and I still backspace that 'e' (elseif) away all too often.

    Your posting helped get me started on today's quest for a solution to the 'price-as-float' issue, and I just wanted to point out some of the other potential workarounds I found. I detailed my search here, but the simple version is that I ended up going with the dollars_and_cents plugin.

    Thanks for the informative article, and welcome to rails!

  9. TheBlatherskite,

    Thanks for the feedback, it's always nice to know you've helped someone out (kinda makes the hours spent hitting my head against a brick wall worthwhile!).

    I'll bear the dollars_and_cents plugin in mind when doing more Ruby coding (which I haven't for a while).