Ruby on Rails Tuesday, June 1, 2010

you could create a method called


def leading_zeros(number)
  "%05d" % number
end

and then call it 

"#{leading_zeros order.id}#{order.name}"

What you have with ""#{order.id}".leading_zeros

is that #{order.id} will evaluate to a string and then you are trying to call the leading_zeros method on the string. For it to work as you intend leading_zeros needs to be part of the String class.

There is no end of pain in doing this.

Just save leading_zeros as a helper method in the application helps and call it as I have shown.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment